MySQL數(shù)據(jù)庫(kù)列的增刪改實(shí)現(xiàn)方法
本文實(shí)例講述了MySQL數(shù)據(jù)庫(kù)列的增刪改實(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)在表的最后一列
語(yǔ)法:alter table 表名 add 列名 列類型 列屬性
alter table user_info add height tinyint unsigned not null default 0;
刪除列
語(yǔ)法:alter table 表名 drop 列名
alter table user_info drop height;
增加列,放在指定列之后
語(yǔ)法:alter table 表名 add 列名 類型 屬性 [默認(rèn)值] after 指定列名
alter table user_info add height tinyint not null default 0 after username;
修改指定列名
語(yǔ)法:alter table 表名 change 舊列名 新列名 類型 屬性 默認(rèn)值
alter table user_info change height shengao smallint not null default 0;
modify 修改列,但不能修改列名
語(yǔ)法: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存儲(chǔ)過(guò)程技巧大全》及《MySQL數(shù)據(jù)庫(kù)鎖相關(guān)技巧匯總》
希望本文所述對(duì)大家MySQL數(shù)據(jù)庫(kù)計(jì)有所幫助。
版權(quán)聲明:本站文章來(lái)源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請(qǐng)保持原文完整并注明來(lái)源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非maisonbaluchon.cn所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來(lái)源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來(lái),僅供學(xué)習(xí)參考,不代表本站立場(chǎng),如有內(nèi)容涉嫌侵權(quán),請(qǐng)聯(lián)系alex-e#qq.com處理。
關(guān)注官方微信