MySQL statement Daquan--------Add columns, modify columns, delete columns

Source: Internet
Author: User

ALTERTABLE:添加,修改,删除表的列,约束等表的定义。

查看列: 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);Modify default value: ALTER TABLE sys_company ALTER COLUMN o2o_company_id set default ' 0 '; sp_rename:SQLServer 内置的存储过程,用与修改表的定义。

MySQL statement Daquan--------Add columns, modify columns, delete columns

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.