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;