本文實(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ǔ)過程技巧大全》及《MySQL數(shù)據(jù)庫(kù)鎖相關(guān)技巧匯總》
希望本文所述對(duì)大家MySQL數(shù)據(jù)庫(kù)計(jì)有所幫助。
您可能感興趣的文章:- MySQL數(shù)據(jù)庫(kù)存儲(chǔ)過程和事務(wù)的區(qū)別講解
- Mysql數(shù)據(jù)庫(kù)的QPS和TPS的意義和計(jì)算方法
- mysql數(shù)據(jù)庫(kù)太大了如何備份與還原
- PHP后臺(tái)備份MySQL數(shù)據(jù)庫(kù)的源碼實(shí)例
- 使用shell腳本每天對(duì)MySQL多個(gè)數(shù)據(jù)庫(kù)自動(dòng)備份的講解
- PHP5中使用mysqli的prepare操作數(shù)據(jù)庫(kù)的介紹
- MySQL數(shù)據(jù)庫(kù)遷移快速導(dǎo)出導(dǎo)入大量數(shù)據(jù)
- shell腳本操作mysql數(shù)據(jù)庫(kù)刪除重復(fù)的數(shù)據(jù)
- insert和select結(jié)合實(shí)現(xiàn)"插入某字段在數(shù)據(jù)庫(kù)中的最大值+1"的方法
- 談?wù)剶?shù)據(jù)庫(kù)的字段設(shè)計(jì)的幾個(gè)心得