MySQL簡(jiǎn)單操作之a(chǎn)lter table改變表的結(jié)構(gòu)
我們知道,MySQL數(shù)據(jù)庫常常與PHP結(jié)合來開發(fā)出功能強(qiáng)大的應(yīng)用程序。那么對(duì)于我們初學(xué)PHP編程的人來說,就很有必要了解一些MySQL數(shù)據(jù)庫的簡(jiǎn)單操作了。本文我們對(duì)MySQL數(shù)據(jù)庫使用alter table語句來修改表結(jié)構(gòu)的知識(shí)進(jìn)行了介紹,接下來就讓我們來一起了解一下這部分內(nèi)容。
1. 增加列
alter table tbl_name add col_name type
例如, 給pet的表增加一列 weight,
mysql>alter table pet add weight int;
2. 刪除列
alter table tbl_name drop col_name
例如, 刪除pet表中的weight這一列
mysql>alter table pet drop weight;
3. 改變列
分為改變列的屬性和改變列的名字
改變列的屬性——方法1:
alter table tbl_name modify col_name type
例如,改變weight的類型
mysql>alter table pet modify weight varchar(30);
改變列的屬性——方法2:
alter table tbl_name change old_col_name col_name type
例如,改變weight的類型
alter table pet change weight weight varchar(30);
改變列的名字:
alter table tbl_name change old_col_name col_name
例如改變pet表中weight的名字:
mysql>alter table pet change weight wei;
4. 改變表的名字
alter table tbl_name rename new_tbl
例如, 把pet表更名為animal
mysql>alter table pet rename animal;
關(guān)于MySQL數(shù)據(jù)庫alter table改變表結(jié)構(gòu)的知識(shí)就介紹到這里了,接下來我們還會(huì)介紹一些MySQL數(shù)據(jù)庫的簡(jiǎn)單操作方法,希望本次的介紹能夠?qū)δ兴斋@吧!
【編輯推薦】


2011-08-24 09:45:14




