約束以及修改數(shù)據(jù)表

image.png

image.png
image.png

image.png

還有一個是alter table users1 add truename varchar(20) not null first;
就是加一列到開頭。

image.png
image.png

image.png
image.png

image.png
image.png

alter table users2 add unique(username);

image.png

alter table users2 add foreign key(pid)references provinces (id);


image.png

alter table users2 alter age set default 15;
alter table users2 alter age drop default;

image.png

alter table users2 drop primary key;

image.png

image.png

alter table users2 drop index usersname;


image.png
image.png

image.png

image.png
image.png

alter table users2 modify id smallint unsigned not null first;
把id放到第一列
alter table users2 modify id tinyint unsigned not null first;
把id放到第一列并且修改數(shù)據(jù)類型,但是從smallint到tinyint可能會造成數(shù)據(jù)丟失。

image.png

alter table users2 change pid p_id tinyint unsigned not null;
把pid改成p_id并且修改數(shù)據(jù)類型

image.png

alter table users2 rename users3;
rename table users3 to users2;
可以用show tables 來查看這個數(shù)據(jù)庫中的所有數(shù)據(jù)表

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容