[MySQL] alter table 增加、刪除、修改欄位型別
阿新 • • 發佈:2021-09-04
經常需要手動增加、刪除、修改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 notnull 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 '線索工種';