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;

相关文章
相关标签/搜索