MySQL數(shù)據(jù)庫列的增刪改實(shí)現(xiàn)方法
本文實(shí)例講述了MySQL數(shù)據(jù)庫列的增刪改實(shí)現(xiàn)方法。分享給大家供大家參考,具體如下:
新建表user_info:
CREATE TABLE user_info( id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, username CHAR(20) NOT NULL DEFAULT '', gender TINYINT UNSIGNED NOT NULL DEFAULT 0, weight TINYINT UNSIGNED NOT NULL DEFAULT 0 )ENGINE=MyISAM DEFAULT CHARSET=utf8;
新增列默認(rèn)在表的最后一列
語法:alter table 表名 add 列名 列類型 列屬性
alter table user_info add height tinyint unsigned not null default 0;
刪除列
語法:alter table 表名 drop 列名
alter table user_info drop height;
增加列,放在指定列之后
語法:alter table 表名 add 列名 類型 屬性 [默認(rèn)值] after 指定列名
alter table user_info add height tinyint not null default 0 after username;
修改指定列名
語法:alter table 表名 change 舊列名 新列名 類型 屬性 默認(rèn)值
alter table user_info change height shengao smallint not null default 0;
modify 修改列,但不能修改列名
語法:alter table 表名 modify 列名 類型 屬性 默認(rèn)值
alter table user_info modify shengao tinyint not null default 0;
更多關(guān)于MySQL相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《MySQL常用函數(shù)大匯總》、《MySQL日志操作技巧大全》、《MySQL事務(wù)操作技巧匯總》、《MySQL存儲過程技巧大全》及《MySQL數(shù)據(jù)庫鎖相關(guān)技巧匯總》
希望本文所述對大家MySQL數(shù)據(jù)庫計(jì)有所幫助。
相關(guān)文章

實(shí)例驗(yàn)證MySQL|update字段為相同的值是否會記錄binlog

通過sysbench工具實(shí)現(xiàn)MySQL數(shù)據(jù)庫的性能測試的方法

MySQL日志專項(xiàng)之redo log和undo log介紹

MySQL中truncate誤操作后的數(shù)據(jù)恢復(fù)案例