Home > Database > Mysql Tutorial > body text

MySQL 添加列,修改列,删除列_MySQL

WBOY
Release: 2016-06-01 13:26:32
Original
1018 people have browsed it

bitsCN.com

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 表名 change  要改变的列名(eg:xxx) 要变成的列(eg:yyy) float;//float为列的类型,可以为char,int,date等其它类型
  • 修改列名SQLServer:exec sp_rename't_student.name','nn','column';
  • 修改列名Oracle:alter table 表名 rename column column1 to column2;
  • 修改列属性:alter table 表名 modify column1 varchar(32);

sp_rename:SQLServer 内置的存储过程,用与修改表的定义。

bitsCN.com
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!