首页 > 其他 > 详细

修改表结构

时间:2020-05-14 21:03:11      阅读:35      评论:0      收藏:0      [点我收藏+]

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;

修改表结构

原文:https://www.cnblogs.com/ch2020/p/12890892.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!