2019-05-16 DDL

一、数据库

1.创建数据库

CREATE DATABASE BOOKS;
CREATE DATABASE IF NOT EXISTS BOOKS;

2.删除数据库

DROP DATABASE BOOKS;
DROP DATABASE IF EXISTS BOOKS;

二、表

1.创建表

CREATE TABLE JOB_GRADES(
    GRADE_LEVEL VARCHAR(3),
    LOWEST_SAL  INT,
    HIGHEST_SAL INT);

2.修改表

①.修改列名
ALTER TABLE BOOK CHANGE COLUMN PUBLISHDATE PUBDATE DATETIME 
②.修改列的类型或约束
ALTER TABLE BOOK MODIFY COLUMN PUBDATE TIMESTAMP;
③.新增列
ALTER TABLE AUTHOR ADD COLUMN ANNUAL DOUBLE;
④.删除列
ALTER TABLE AUTHOR DROP COLUMN ANNUAL;
⑤.修改表名
ALTER TABLE AUTHOR RENAME TO AUTHORR

3.删除表

DROP TABLE IF EXISTS BOOK_AUTHOR;

4.复制表

CREATE TABLE COPY LIKE AUTHOR; -- 仅仅复制表结构
CREATE TABLE COPY1 SELECT * FROM AUTHOR; -- 复制表的结构+数据
CREATE TABLE COPY3 SELECT ID,AU_NAME FROM AUTHOR WHERER NATION = ''; -- 只复制部分数据

你可能感兴趣的:(2019-05-16 DDL)