cwx 发表于 2018-10-7 14:14:37

MySQL--数据表操作

| 表的创建  
create table 表名(字段名 类型名 约束)
  
# create table students(
  
    id int unsigned primary key auto_increment not null,
  
    name varchar(20) default '',
  
    age tinyint unsigned default 0,
  
    height decimal(5,2),
  
    gender enum('男','女','人妖','保密'),
  
    cls_id int unsigned default 0
  
);
  
# create table classes(
  
    id int unsigned auto_increment primary key not null,
  
    name varchar(10)
  
);
  
| 查看数据库中所有表
  
show tables;
  
| 查看创建语句
  
show create table classes;
  
| 查看表结构,描述表
  
desc classes;
  
- 修改字段
  
| 修改表-添加字段 add
  
alter table students add birthday datetime;
  
| 修改表-修改字段:不重命名版 modify
  
alter table students modify birthday date;
  
| 修改表-修改字段:重命名版 change
  
alter table students change birthday birth date;
  
| 修改表-删除字段 drop
  
alter table students drop high;
  
| 删除表
  
drop table students;


页: [1]
查看完整版本: MySQL--数据表操作