//主鍵
ALTER TABLE tablename add new_field_id int(5) UNSIGNED DEFAULT 0 NOT NULL anto_increment,ADD PRIMARY KEY (new_field_id);
//增加一個新列
mysql>ALTER TABLE tablename ADD fieldname fieldtype
如:
ALTER TABLE t2 ADD d TIMESTAMP;
ALTER TABLE infos ADD ex TINYINT NOT NULL DEFAULT '0';
//刪除列
mysql>ALTER TABLE table_name DROP field_name
如:
ALTER TABLE t2 DROP COLUMN c;
//修改原字段名稱及類型
mysql>ALTER TABLE tablename CHANGE old_field_name new_field_name field_type;
如:
//重命名列
ALTER TABLE t1 CHANGE a b INTEGER;
//改變列的類型
ALTER TABLE t1 CHANGE b b BIGINT NOT NULL;
ALTER TABLE infos CHANGE list list TINYINT NOT NULL DEFAULT '0';
//重命名表
ALTER TABLE t1 RENAME t2;
//加索引
mysql>ALTER TABLE tablename CHANGE depno depno int(5) NOT NULL;
mysql>ALTER TABLE tablename ADD INDEX 索引名 (字段名1[,字段名2……]);
mysql>ALTER TABLE tablename ADD INDEX emp_name(name);
//加主關鍵字的搜索
mysql>ALTER TABLE tablename ADD PRIMARY KEY(id);
//加唯一限制條件的索引
mysql>ALTER TABLE tablename ADD UNIQUE emp_name2(cardnumber);
//刪除某個索引
mysql>ALTER TABLE tablename DROP INDEX emp_name;