1.修改表结构
增加表字段:alter table Categories add column title varchar(255);
删除表字段:alter table Categories drop column title;
修改表字段:alter table Categories change title title_id int;
2.增加主键/删除
alter table Categories add primary key (id);增加主键
alter table Categories change id id int(11) not null auto_increment;增加主键不为空,自增长属性
主键删除前必须删除自增长才能删除成功
alter table Posts change id id int;删除自增长
alter table Posts drop primary key;删除主键
3.增加外键,外键删除
alter table Categories add constraint fk_flag foreign key(user_id) references Users(id);增加外键
alter table Categories drop foreign key fk_flag;删除外键