修改表結構

2022-05-06 06:00:07 字數 908 閱讀 2630

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;

修改表結構

add column create definition first after column name 新增新字段 add index index name index col name,新增索引名稱 add primary key index col name,新增主鍵名稱 add unique...

修改表結構

1.alter操作表字段 1 增加字段 alter table 表名 add 欄位名 字段型別 alter table student add name varchar 10 2 修改字段 alter table 表名 change 舊欄位名 新欄位名 字段型別 alter table 表名 mod...

mysql 修改表結構

1.mysql 修改表名字 alter table t1 rename t2 2.修改列的名字 alter table stock change column stock id id int 6 3.增加列 alter table ab add column id int 3 4.減少列 alter...