modify、rename、change的使用及区别
modify
--用于修改字段中的数据约束rename
--用于修改表名和字段名change
--重新定义字段,包括了字段名和字段的数据约束
说下具体用法吧
1.修改字段类型
alter table 表名 modify 字段名 新数据类型;
2.修改表名
- 写法一:
rename table 旧表名 to 新表名;
- 写法二:
alter table 旧表名 rename to 新表名;
3.修改字段名
alter table 表名 rename column 旧字段名 to 新字段名;
4.重新定义字段
alter table 表名 change 旧字段名 新字段名 新数据类型
mysql的alter,change,modify用法
- 修改某一列,列名不改变,用modify
alter table order modify order_fee decimal(14,4) default null;
- 修改某一列,列名要改变,用change
alter table apps change column at_p1 at_p2 decimal(8,4) null default null comment ‘test111' after status_id;
- 增加一列
alter table apps add column op_date datetime(0) null comment ‘创建时间' after op_user;
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。
发表评论