01
—
课程介绍
这是系统学习SQL语言的课程,课程中的所有SQL语句完全兼容MySQL、Oracle、SQL Server和PostgreSQL等4种最流行的数据库,实际上也可以兼容几乎所有的数据库。
目标学员:
- 零基础的同学系统学习SQL语言。
- 有一定基础的同学对自己的SQL语言知识进行查漏补缺。
02
—
实验环境
4种数据库的客户端都是最流行的,也是自带,无需单独安装。
课程中会随机在这4种数据库上面进行实验,同一个实验只会在一种数据库上面做一次,而不会在4种数据库上面做四次,因为所有是SQL语句都是同时兼任着4种数据库的。大家花一份时间有4倍的收获。本课程以实验为导向进行编排,同学们不要看到实验只在某一种数据库上面做就以为不兼容自己的数据库,都是兼容的。
03
—
创建样本数据的脚本
-- 创建部门表drop table job_history;drop table employees;drop table departments;create table departments( deptno int primary key, dname varchar(12) not null, managerno int, loc varchar(10));-- 向部门表中插入记录insert into departments values(1,'开发部',2,'一楼');insert into departments values(2,'测试部',3,'二楼');insert into departments values(3,'销售部',8,'一楼');insert into departments values(4,'新业务部',null,'二楼');-- 创建员工表create table employees( empno int primary key , name char(10) not null, deptno int, email varchar(20), hiredate date, salary numeric(8, 2) default 8000.00, FOREIGN KEY(deptno) REFERENCES departments(deptno));-- 向员工表中插入记录insert into employees values(1,'周福生',NULL,'zhou@gmail.com','2000-12-02',90000.00);insert into employees values(2,'王五',1,'wangsu@gmail.com','2013-01-03',9100.00);insert into employees values(3,'李四',2,'lisi@qq.com','2021-02-10',13900.00);insert into employees values(4,'赵六',1,'zhaoliu@qq.com','2022-12-1',15000.00);insert into employees values(5,'李明',1,'liming@qq.com','2004-09-11',25200.00);insert into employees values(6,'孙军',2,'sunjun@163.com','2016-05-22',9700.00);insert into employees values(7,'钱杰',3,'qianjie@outlook.com','2013-07-22',8900.00);insert into employees values(8,'程娟',3,'chengjuan@gmail.com','2013-07-22',14900.00);insert into employees values(9,'赵卫华',1,'zhaoweihua@gmail.com','2009-11-12',21900.00);-- 创建岗位历史表create table job_history( empno int, start_date date, end_date date, deptno int, PRIMARY KEY(empno,start_date), FOREIGN KEY(empno) REFERENCES employees(empno));-- 向岗位历史表中插入数据insert into job_history values(2,'2013-01-03','2015-12-31',3);insert into job_history values(2,'2016-01-01','2018-12-31',2);insert into job_history values(3,'2015-01-01','2017-12-31',2);insert into job_history values(4,'2010-01-01','2015-12-31',1);insert into job_history values(5,'2015-06-30','2016-12-31',2);insert into job_history values(9,'2009-11-12','2010-12-31',1);commit;select * from departments;select * from employees; select * from job_history;