本文實(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;
希望本文所述對大家MySQL數(shù)據(jù)庫計有所幫助。