创建数据库:create database 数据库名;
修改数据库:alter database 数据库名
character set 字符集名
collate 字符校对规则;
删除数据库:drop database 数据库名;
创建表: create table 表名
(列名 列的数据类型 列的约束, ...);
修改表: alter table 表名
1.添加列: add 列名 列的数据类型 列的约束
2.修改列的数据类型: modify 列名 新数据类型 新约束
3.修改列的默认值:alter 列名 set default 默认值| drop default
4.修改列的名字:change 旧列名 新列名 列定义
5.删除列:drop 列名
6.将字符集转换为二进制:convert to character set 字符集名字 ;
删除表:drop table 表名;
重命名表:1、alter table 旧表名
rename 新表名;
2、rename table 旧表名 to 新表名;
向表中插入数据:insert into 表名(列名,...) values(值,...);
修改表中的数据:update 表名 set 列名=新的列值 where 更新条件;
删除表中的数据:delete from 表名 where 删除条件;
查询数据:select [distinct(去除重复行)] 结果列,...结果列 as 新列名
from 表1,表2,....
where 条件(查询条件,连接条件)
group by 分组的列名 asc | desc
with rollup
having 分组以后筛选的条件
order by 要排序的关键字1,关键字2 asc |desc
limit n| n,m ;
多个select语句链接使用:union
创建视图:create view 视图名 as select查询语句 with check option;
更新视图: insert 视图名 (同表的操作)
(对视图当中的 update 视图名
数据进行操作) delete 视图名
修改视图:alter view 视图名 as select查询语句 with check option;
删除视图:drop view 视图名;
创建索引:1、create index 索引名 [using 索引类型]
on 表名(列名(长度),...);
2、create table 表名(列定义,.. index 索引名 [using 索引类型](列名));
3、alter table 表名
add index 索引名 using 索引类型(列名);
删除索引:1、drop index 索引名 on 表名;
2、alter table 表名
drop index 索引名;