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放到第一列并且修改數據類型,但是從smallint到tinyint可能會造成數據丟失。
image.png
alter table users2 change pid p_id tinyint unsigned not null;
把pid改成p_id并且修改數據類型
image.png
alter table users2 rename users3;
rename table users3 to users2;
可以用show tables 來查看這個數據庫中的所有數據表