文章目录
1. DDL数据定义语言1.1 库的管理1.2 表的管理
1. DDL数据定义语言
1.1 库的管理
create database if not exists books
;
rename database books
to 新库名
;
alter database books
character set gbk
;
drop database if exists books
;
1.2 表的管理
create table
book
( id
int,
bName
varchar(20),
price
double,
authorId
int,
publishDate
datetime );
create table
if not exists author
( id
int,
au_name
varchar(20),
nation
varchar(10) );
alter table
book change
column publishdate pubDate
datetime;
alter table
book
modify column pubdate
timestamp;
alter table
author
add column annual
double;
alter table
book_author
drop column annual
;
alter table
author
rename to book_author
;
drop table
if exists book_author
;
drop database if exists 旧库名
;
create database 新库名
;
drop table if exists 旧表名
;
create table 表名
();
insert
into
author
values (1,
'村上春树',
'日本'),
(2,
'莫言',
'中国'),
(3,
'冯唐',
'中国'),
(4,
'金庸',
'中国');
create table
copy
like author
;
create table
copy2
select
*
from
author
;
create table
copy3
select
id
,
au_name
from
author
where
nation
= '中国';
create table
copy4
select
id
,
au_name
from
author
where
0;
转载请注明原文地址:https://tech.qufami.com/read-3385.html