表的管理

一、表的创建

create table 表名 (

  列名 列的类型【(长度) 约束】,

  列名 列的类型【(长度) 约束】,

  列名 列的类型【(长度) 约束】

);

#案例:创建表book

creat table book(

  id int,

  b_name varchar(20), #图书名

  price double,

  author_id int , #作者名

  publish_date datetime #出版日期

#创建表author实现分类存储

creat table author(

  id int,

  au_name varchar(20),

  nation varchar(10)

) ;

二、表的修改

#1.修改列名

alter table 表名 change column 旧列名 新列名 类型;

alter table book change column publishdate pubdate datetime ;

#2.修改列的类型或约束

alter table 表名 modify column 列名,类型;

alter table book modify column pubdate timestamp;

#3.添加列

alter table 表名 add column 列名,类型;

alter table 表名 add column annual double ;

#4.删除列

alter table 表名 drop column 列名;

alter table author drop column if exist annual ;

#5.修改表名

alter table 表名 rename to 新表名;

alter table author rename to writer;

posted @ 2022-12-16 13:46  平凡的柳先生  阅读(16)  评论(0)    收藏  举报