Mysql
#修改字段类型、字段注释、字段默认值
ALTER TABLE 表名 MODIFY [COLUMN] 字段名 新数据类型 新类型长度 新默认值 新注释;
-- COLUMN关键字可以省略不写
alter table box modify column boxnum varchar(40) not null comment '编号'
mysql修改字段名:
ALTER TABLE 表名 CHANGE [column] 旧字段名 新字段名 新数据类型;
alter table table1 change column1 column1 varchar(100) DEFAULT 1.2 COMMENT '注释'; -- 正常,此时字段名称没有改变,能修改字段类型、类型长度、默认值、注释
alter table table1 change column1 column2 decimal(10,1) DEFAULT NULL COMMENT '注释' -- 正常,能修改字段名、字段类型、类型长度、默认值、注释
alter table table1 change column2 column1 decimal(10,1) DEFAULT NULL COMMENT '注释' -- 正常,能修改字段名、字段类型、类型长度、默认值、注释
alter table table1 change column1 column2; -- 报错
alter table box CHANGE column boxnum boxid varchar(30) not null comment '编号'
ALTER TABLE 旧表名 RENAME TO 新表名
alter table hezi rename to box
ALTER TABLE 表名 COMMENT '新注释'
alter table box comment '座位表'
ALTER TABLE 表名 ADD [COLUMN] 字段名 字段类型 是否可为空 COMMENT '注释' AFTER 指定某字段 ;
--COLUMN关键字可以省略不写
alter table box add column boxroom varchar(30) not null comment '座位空间' after boxname
ALTER TABLE 表名 ADD COLUMN newname 数据类型 数据长度 默认值 注释
//增加一个字段,默认为空
alter table box add column boxroom int 10 default null comment '座位空间'
//增加一个字段,默认不为空
alter table box add column boxroom int 10 not null comment '座位空间'
ALTER TABLE 表名 DROP [COLUMN] 字段名 ;
--COLUMN关键字可以省略不写
alter table box drop boxroom