修改表结构

1.修改表名

alter table 表名
2.添加一个字段

ater table 表名   add  字段名   数据类型[约束条件];add  字段名   数据类型[约束条件];

 

3.将添加的字段放在某个字段之后,    放在最前面用first

alter   table   表名    add  字段名    数据类型[约束条件]  after  字段名;

修改主键

alter   table   student2  drop   primary  key;

然后再添加主键

alter  table   student2   add  primary  key(id);(添加前要删除重复的值)

为book表添加外键

alter  table book  add  constraint  fk_id  foreign   key(press_id)  references  press(id);

删除外键

alter   table   book   drop   foreign  key   fk_id;

4.删除字段名

alter   table   表名   drop  字段名;

5.修改字段   modify      char(15)变为char(19)

alter table student2 modify name char(18);      不能修改字段名,只能改类型。

可以去掉not  null             alter   table   student2   modify  name  char(12)  null;

change

alter  table  student2   change  name  sname   char(10) not null;

posted @ 2020-05-14 19:28  竹石2020  阅读(970)  评论(0编辑  收藏  举报