ddl 数据库操作
-
show databases ; 查询所有数据库
-
select databae(); 查询当前数据库
-
creat database ; 创建数据库
如果数据库存在就会报错 可以用 creat database if not exists 数据库名
-
drop databse 数据库名 ;删除数据库
-
use 数据库名 ; 使用该数据库
ddl 表操作
-
show tables ; 展示所有表
-
desc 表名 ; 查询表结构
-
show creat table 表名 ; 查询指定表的建表语句
-
creat table 表明 (
字段1 字段1类型 comment注释 ,
字段1 字段1类型 comment注释 ,
字段1 字段1类型 comment注释
)[comment表注释] ;
数值类型
字符串类型
varhcar 变长字符串 char定长字符串
日期类型
create table emp
(
num int comment"编号",
worknum int comment"工号",
gender char(1) comment"性别",
name varchar(10) comment "名字",
age tinyint unsigned comment "年龄",
id char(18) comment"编号",
day date comment "入职日期"
)comment "员工表";
表操作
添加字段
alter table 表名 add 字段名 类型(长度)comment'注释' ;
修改
修改数据类型
alter table 表名 modify 字段名 类型(长度) ;
修改字段名和字段类型
alter table 表名 change 旧字段名 新字段名 类型(长度)comment ;
alter table emp change name workname varchar(10) comment'工号';
删除字段
alter table 表名 drop 字段名 ;
修改表名
alter table 表名 rename to 新表名 ;
删除表
删除
drop table【if exists】表名 ;
删除并重建
truncate table 表名;