DDL

2021-03-09spa

數據定義語言庫和表的管理io

1、庫的管理table

建立、修改、刪除date

2、表的管理select

建立、修改、刪除語法

 

建立:createim

修改:alter數據

刪除:droptab

 

1、庫的管理語言

1.庫的建立

(能夠右鍵) 

語法:create database 庫名

例子:create database if not exists books

2.庫的修改

alter database books character set gbk(更改庫的字符集)

 

3.庫的刪除

drop database if exists books

 

2、表的管理

1.表的建立※

語法:

create table 表名(

    列名 列的類型 【(長度)約束】,

    列名 列的類型 【(長度)約束】,

    列名 列的類型 【(長度)約束】,    

    列名 列的類型 【(長度)約束】,

)

案例:

create table book(

    id int,

    bname varchar(20),

    price double,

    authorid int,

    publishdata datebase

);

2.表的修改

①修改列名

  alter table book chance column publishdata pubData DataTime(修改的時候還得加類型,也能夠順便改個類型)

②修改列的類型或約束

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 book_author

 

3.表的刪除

drop table  if exists bool_author

 通用的寫法

drop database if exists 舊庫名

create database 新庫名

 

drop table if exists 舊錶名

create table 表名()

 

4.表的複製

create table copy like anthor(僅能複製表的結構)

 

create table copy2 select * from author(複製表的結構+數據)

 

create table copy3 select id,name

from ahthor

where country='中國' (僅複製部份數據)

 

create table copy4 (僅複製某些字段)

select id,au_name

from author

where 0;

相關文章
相關標籤/搜索