DDL数据库定义语言
数据库定义语言DDL
create
创建数据库
create database [if not exists] 库名 [create_option] //括号中内容为可选内容
[create_option] : [default] {
character set [=] utf8 //设置编码名utf8为其中一种编码格式
| collate [=] collaction_name
| encryption [=] {‘Y’,‘N’} //是否开启加密
}
删除数据库
drop database 库名
创建表
create [temporary] table [if not exists] 表名 (列名 列类型 [null]| 默认值 约束,列名 列类型 [null]| 默认值 约束)
删除表
drop table 表名 //删除表数据和表结构,不会记录日志
truncate table 表名 //截断数据库,删除表记录,会记录日志
delete table 表名 [where] //可加条件,删除表记录,不会删除表结构
修改表结构
添加列
alter table 表名 add 列名 列类型
删除列
alter table 表名 drop column 列名
修改列名
alter table 表名 rename column 老列名 to 新列名
修改新列名
alter table 表名 change column 老列名 新列名 新列类型
修改表名
alter table 表名 rename 老列名 to 新列名