Mysql 修改列,增加列,刪除列常用指令,mysql指令

來源:互聯網
上載者:User

Mysql 修改列,增加列,刪除列常用指令,mysql指令

ALTER TABLE:添加,修改,刪除表的列,約束等表的定義。

查看列:desc 表名;

修改表名: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;

修改列名SQLServer:exec sp_rename't_student.name','nn','column';

修改列名Oracle:lter table bbb rename column nnnnn to hh int;

修改列屬性:alter table t_book modify name varchar(22);sp_rename:SQLServer 內建的預存程序,用與修改表的定義。

MySQL 查看約束,添加約束,刪除約束 添加列,修改列,刪除列查看錶的欄位資訊:desc 表名;

查看錶的所有資訊: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 外鍵(區分大小寫);

修改表名: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;

修改列名SQLServer:exec sp_rename't_student.name','nn','column';

修改列名Oracle:alter table bbb rename column nnnnn to hh int;

修改列屬性:alter table t_book modify name varchar(22);sp_rename:SQLServer 內建的預存程序,用與修改表的定義。

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.