(一)、首先给sql<结构化查询语句>分类
-- DDL <数据定义语言>
--create
create database db_name;
create table table_name (list_name list_type [constraint]);
--drop
drop database db_name;
drop table table_name;
--alter
alter table table_name add new_list list_type [constraint];
alter table table_name add 属性 属性名 [list];
alter table table_name drop old_list;
alter table table_name drop index index_name;
alter table table_name change old_list new_list list_type [constraint];
-- DML<数据操作语言>
--insert
insert into table_name[(list_name)] values(list_values);
--delete
delete * from table_name;
delete from table_name where list_name = list_value;
--update
update table table_name set list_name = list_new_value where list_name =list_old_value;
--select
select [distinct] list_name from table_name;
-- DCL<数据控制语言>
--crant
--deny
--revoke
-- TCL<事务控制语言>
--commit
--rollback
--savepoint
(二)、关键字
-- 操作符
and & or
like '_' , '%'
in
between...and
union
null
1、函数ifnull(list_name , 0);
2、is null例句:select list_name from table where list_name is [not] null;
order by
limit
where
1、where用途:筛选数据
2、where子句的返回结果:0,1; 0代表false,1代表true;
3、判断条件
比较运算符:>,<,=,!=/<>,>=,<=,like,between and,[not] in;
逻辑运算符:&&(and),||(or),!(not);
4、例子
select * from student where id = 1 || id = 2 || id = 3;
select * from student where id in(1,2,3);
select * from student where age >= 18 and age <=20;
select * from student where age between 18 and 20;
-- 约束
not null
unique
primary key
foreign key
default
-- 别名
1、list_name as 别名;
2、table_name 别名;
-- 视图
view
-- 索引
index
1、创建索引:create [unique] index index_name on table_name(list_name);
2、删除索引:drop index index_name;
-- 聚合函数
sum()
svg()
count()
max()
min()