SQL 中最重要的 DDL 语句:
CREATE DATABASE - 创建新数据库
ALTER DATABASE - 修改数据库
CREATE TABLE - 创建新表
ALTER TABLE - 变更(改变)数据库表
DROP TABLE - 删除表
CREATE INDEX - 创建索引(搜索键)
DROP INDEX - 删除索引
SQL语句的DML 部分:
SELECT - 从数据库表中获取数据
UPDATE - 更新数据库表中的数据
DELETE - 从数据库表中删除数据
INSERT INTO - 向数据库表中插入数据
SQL的DQL的基本语法
select+字段列表 | 基本查询 |
from+表名列表 | 基本查询 |
where+条件列表 | 条件查询 |
group by+分组字段列表 | 分组查询 |
having+分组后条件列表 | 分组查询 |
order by+排序字段列表 | 排序查询 |
limt+分页参数 | 分页查询 |
-- 分页
select *from student limit 2,3; -- 公式 (页码-1)*步长 -- 外联查询
-- left join on 左外联
-- right join on 右外联
select *from student left join class on student.classid= class.classid;-- 左外联
union
select *from student right join class on student.classid=class.classid; -- 右外联
use myschool;
group by 分组
select student.sid,sname,avg(score) a from student,sc where student.sid=sc.sid
group by sid having a>=60
like % 模糊查询
select count(*) from teacher where tname like '李%'
desc 降序
检索” 01 “课程分数小于 60,按分数降序排列的学生信息
select * from sc left join student on sc.sid = student.sid where score < 60 and cid = 1 order by score desc