0420-mysql命令(数据库操作层级,建表,对表的操作)

注意事项:

符号必须为英文。

数据库操作层级:

建表大全:

#新建表zuoye1;
drop table if exists zuoye1;
create table zuoye1(
    id int auto_increment not null,    #字段名id,整数类型,自增长,不可为空
    f1 float comment '小数类型',
    f2 decimal(20,5) default 12.3,    #数据长度20,小数点后5位,默认值12.3
    f4 varchar(20) comment '字符串类型,数据长度20',
    id2 int,        #意图作为某个表的外键
    primary key(id),    #id设为主键,既是约束,也是索引
    unique key(f1),        #设为唯一键,不可重复。既是约束,也是索引
    key(f2),        #只是索引
    foreign key(id2) references set_test(id)
)
comment = '这是一个建表大全语句',
engine = MyIsam,    #表的类型
auto_increment = 1000;    #自动增长从1000开始

 修改表:

增:alter  table  表名  add  [column]  字段名  字段类型  字段属性;
删: alter  table  表名  drop  字段名
改:alter  table  表名  change  原字段名  新字段名  新字段类型  新字段属性;

原文地址:https://www.cnblogs.com/flypea93/p/8888139.html