DDL 是管理库和表的
库管理 : 创建 修改 删除
表管理: 创建 修改 删除
创建 : create
修改: alter
删除: drop
语法
1 创建xx库 如果不存在xx 就创建
create database if not exists xx;
2 更改库的名字
rename database xx to 新库名字 ;
3.更改字符集
alter database xx character set 新字符集 ;
4库的删除 如果存在 就删除
drop database if exists xx ;
创建表
语法
create table 表名 (
列名 列的数据类型 【(长度) 约束】,
列名 列的数据类型 【(长度) 约束】,
)
数据类型 数字 int
字符串 varchar
时间 datetime
表的 修改
1 修改列名
alter table 表名 change column 原名 想改成的名字 数据类型
2修改列的类型
alter table 表名 modiey column 列名 新的数据类型;
3添加新列
alter table 表名 add column 列明 数据类型 ;
4删除列
alter table 表名 drop column 列名 ;
5修改表名
alter table 表名 rename to 新表名;
表的 删除
drop table if exists 表名 ;
平时通用的写法
drop database if exists 库名
create database 新库名
drop table if exists 表名
create table 表名()
表的复制操作
1.如果单纯只是想复制表的结构
create table 表名 like 想复制的表名 ;
2 如果 要复制 某个表的 全部;
create table 表名 (
select * from 某个表名
)
3 如果复制部分数据
create table 表名(
select * from 某个表名 where 筛选条件
)
原文:https://www.cnblogs.com/Dasnl/p/14683555.html