修改主键和外键

--删除主键并添加新主键
 alter table 表名 drop column 主键名;
 alter table 表名 
    add 主键列名 int not null primary key auto_increment;

--删除约束
alter table 表名 drop constraint 约束名


--添加主键约束
alter table 表名
   add constraint 约束名 primary key(列名);

--添加外键约束
alter table 表名
  add constraint 约束名 foreign key(外键名) references 参照表(列名)  

--修改列定义
alter table 表名
modify 列名 int not null;

--删除列
alter table 表名 drop column 列名;

--修改表名
ALTER   TABLE   table   RENAME   TO   新表名

猜你喜欢

转载自paladin1988.iteye.com/blog/1634445