• 微信
您当前的位置: 首页> LNMP环境> Mysql资料库>

MySQL语句增加字段,修改字段名,修改类型,修改默认值

作者:Alpha时间:2019-09-26 阅读数:3559 +人阅读

增加字段:
alter table 表名 ADD 字段 类型 约束 [默认值 注释]

ALTER TABLE video ADD category_id int(11) unsigned not null DEFAULT '0' COMMENT '视频分类id';



修改字段名:
alter table 表名 rename column A to B

ALTER TABLE video RENAME COLUMN category_id TO cid;



修改字段类型:
alter table 表名 modify column 字段名 类型 约束 [默认值, 注释];

ALTER TABLE video MODIFY COLUMN category_id smallint(5) unsigned not null DEFAULT '0' COMMENT '视频分类id';



修改字段默认值
alter table 表名 alter column 字段名 drop default; --(若本身存在默认值,则先删除)
alter table 表名 alter column 字段名 set default 默认值; --(若本身不存在则可以直接设定)

ALTER TABLE video ALTER COLUMN sort SET DEFAULT '50';


本站所有文章、数据、图片均来自互联网,一切版权均归源网站或源作者所有。

如果侵犯了你的权益请来信告知我们删除。邮箱:595397166@qq.com

标签:

上一篇:SQL实现模糊查询 语法

下一篇:没有了

阿尔法

软件开发工程师#全栈工程师

{include file=foot.html}