MySQL資料庫常用的修改表命令總結

查看列:desc 表名;

查看所有資料庫:show databases;

進入資料庫:use 資料庫名;

查看所有數據表名:show tables;

查看用戶權限情況:select * from mysql.user\G;

修改表名:alter table t_book rename to bbb;?

添加列:alter table 表名 add column 列名 varchar(30);?

刪除列:alter table 表名 drop column 列名;

修改列名MySQL: alter table bbb change nnnnn hh int;?

修改列屬性:alter table t_book modify name varchar(22);?

查看表的所有信息:show create table 表名;

添加主鍵約束:alter table 表名 add constraint 主鍵 (形如:PK_表名) primary key 表名(主鍵字段);

添加外鍵約束:alter table 從表 add constraint 外鍵(形如:FK_從表_主表) foreign key 從表(外鍵字段) references 主表(主鍵字段);

刪除主鍵約束:alter table 表名 drop primary key;

刪除外鍵約束:alter table 表名 drop foreign key 外鍵(區分大小寫);

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *