[MySQL] alter table 增加、删除、修改字段类型


经常需要手动增加、删除、修改mysql表的字段类型,可以参考下面的例子:

 

增加多个字段:

ALTER TABLE `test11` ADD COLUMN (
        `ucid` bigint(20) NOT NULL DEFAULT 0 COMMENT '线索ucid',
        `clue_type` int(11) NOT NULL  DEFAULT '1' COMMENT '线索类型1招生 2招商',
        `work_type` int(11) NOT NULL  DEFAULT 0 COMMENT '线索工种',
        `allottime` TIMESTAMP not null DEFAULT CURRENT_TIMESTAMP COMMENT '分单时间',
        `allot_admin_id` int(11) NOT NULL   DEFAULT 0 COMMENT '分单人id',
        `allot_store_id` int(11) NOT NULL   DEFAULT 0 COMMENT '分单门店'
)

删除多个字段:

ALTER TABLE `test11` DROP `clue_type`,DROP `work_type`,DROP `ucid`;

修改字段:

ALTER TABLE `test11` modify COLUMN  `ucid` bigint(20) NOT NULL DEFAULT 0 COMMENT '线索ucid';
ALTER TABLE `test11` modify COLUMN `clue_type` int(1) NOT NULL  DEFAULT '1' COMMENT '线索类型1招生 2招商';
ALTER TABLE `test11` modify COLUMN `work_type` int(3) NOT NULL  DEFAULT 0 COMMENT '线索工种';

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM