1.增長字段:shell
alter table tablename add new_field_id type not null default '0';
增長主鍵:spa
alter table tabelname add new_field_id type default 0 not null auto_increment ,add primary key (new_field_id);
增長外鍵:code
在已經存在的字段上增長外鍵約束orm
ALTER TABLE yourtablename ADD [CONSTRAINT symbol] FOREIGN KEY [id] (index_col_name, ...) REFERENCES tbl_name (index_col_name, ...) [ON DELETE {RESTRICT | CASCADE | SET NULL | NO ACTION}] [ON UPDATE {RESTRICT | CASCADE | SET NULL | NO ACTION}]
2.刪除字段:rem
alter table tablename drop column colname;
3.修改字段名:it
alter table tablename change old_field_name new_field_name old_type;
4.修改字段類型:table
alter table tablename change filed_name filed_name new_type;
5.修改字段爲空、不爲空class
alter table 表名 modify 字段名 字段類型(長度) null;