MySQL入門知識:用ALTER TABLE語句修改表的結(jié)構(gòu)
最新學訊:近期OCP認證正在報名中,因考試人員較多請盡快報名獲取最近考試時間,報名費用請聯(lián)系在線老師,甲骨文官方認證,報名從速!
我要咨詢MySQL入門知識:用ALTER TABLE語句修改表的結(jié)構(gòu),有時你可能需要改變一下現(xiàn)有表的結(jié)構(gòu),那么Alter Table語句將是你的合適選擇。
增加列
alter table tbl_name add col_name type
例如,給表增加一列weight
mysql>alter table pet add weight int;
刪除列
alter table tbl_name drop col_name
例如,刪除列weight:
mysql>alter table pet drop weight;
改變列
alter table tbl_name modify col_name type
例如,改變weight的類型:
mysql> alter table pet modify weight samllint;
另一種方法是:
alter table tbl_name change old_col_name col_name type
例如:
mysql> alter table pet change weight weight samllint;
給列更名
mysql>alter table pet change weight wei;
給表更名
alter table tbl_name rename new_tbl
例如,把pet表更名為animal
mysql>alter table pet rename animal;
改變表的類型
另外,可以為列增加或刪除索引等屬性,不再詳述,請參閱附錄。
- 陳衛(wèi)星-老師CUUG金牌講師
- 陳老師 CUUG金牌講師 精通Oracle管理、備份恢復(fù)、性能優(yōu)化 11年Ora...[詳細了解老師]
