当前位置:Gxlcms > 数据库问题 > DDL语言(MySQL表的管理)

DDL语言(MySQL表的管理)

时间:2021-07-01 10:21:17 帮助过:3人阅读

Create table 表名 ((列名,数据类型),(列名,数据类型),(列名,数据类型),(列名,数据类型),);

二、表的修改

 1)列的增加(与注释)

  语法:

Alter  table tableName add column columName columnType comment 注释 ;

  案例:

alter table author add column name varchar(20) comment 注释;

 2)列名的修改

  语法:

Alter table tableName change column columnName newColumnName columnType;

  案例:

alter table author change column name  names varchar(20);

 3)列数据类型的修改

  语法:

Alter table tableName modify column columnName columnType comment 注释;

  案例:

alter table author modify column names varchar(10);

 4)列的删除

  语法:

Alter table tableName drop column columnName;

  案例:

alter table author modify column names varchar(10);

 5)表的重命名

  语法:

Alter table tableName rename to newTableName;

  案例:

alter table author rename to authors;

 6)表的复制

  • 全部复制

  语法:

Create table select * from oldtable;

  案例:

create copy3 select * from authors;
  • 部分复制

  语法 :

Create table newTable select column1,column2,column3 from oldtable;

  案例:

create table copy2 select id,author from authors;
  • 结构复制

  语法:

Alter table newTableName like tableName;

  案例:

create table copy like authors;

 三、表的删除

  语法:

drop table table1,table2,table3;

  案例:

drop table copy,copy2,copy3;

 

DDL语言(MySQL表的管理)

标签:com   code   sql   类型   rom   部分   sel   ble   表名   

人气教程排行