標籤:
alter add命令用來增加表的欄位。
alter add命令格式:alter table 表名 add欄位 類型 其他;
例如,在表MyClass中添加了一個欄位passtest,類型為int(4),預設值為0:
mysql> alter table MyClass add passtest int(4) default ‘0‘;
1) 加索引
mysql> alter table 表名 add index 索引名 (欄位名1[,欄位名2 …]);
例子: mysql> alter table employee add index emp_name (name);
2) 加主關鍵字的索引
mysql> alter table 表名 add primary key (欄位名);
例子: mysql> alter table employee add primary key(id);
3) 加唯一限制條件的索引
mysql> alter table 表名 add unique 索引名 (欄位名);
例子: mysql> alter table employee add unique emp_name2(cardnumber);
4) 刪除某個索引
mysql> alter table 表名 drop index 索引名;
例子: mysql>alter table employee drop index emp_name;
5) 增加欄位
mysql> ALTER TABLE table_name ADD field_name field_type;
6) 修改原欄位名稱及類型
mysql> ALTER TABLE table_name CHANGE old_field_name new_field_name field_type;
7) 刪除欄位
mysql> ALTER TABLE table_name DROP field_name;
mysql alter add 使用記錄