Skip to content

Commit ea9adc6

Browse files
committed
更新了部分文档
1 parent 4d9f270 commit ea9adc6

File tree

3 files changed

+3296
-54
lines changed

3 files changed

+3296
-54
lines changed
Lines changed: 56 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,55 @@
1-
-- 创建人力资源管理系统数据库
2-
drop database if exists HRS;
3-
create database HRS default charset utf8;
4-
-- 切换数据库上下文环境
5-
use HRS;
6-
-- 删除表
7-
drop table if exists TbEmp;
8-
drop table if exists TbDept;
9-
-- 创建部门表
10-
create table TbDept
1+
drop database if exists hrs;
2+
create database hrs default charset utf8;
3+
4+
use hrs;
5+
6+
drop table if exists tb_emp;
7+
drop table if exists tb_dept;
8+
9+
create table tb_dept
1110
(
12-
deptno tinyint primary key, -- 部门编号
13-
dname varchar(10) not null, -- 部门名称
14-
dloc varchar(20) not null -- 部门所在地
11+
dno int not null comment '编号',
12+
dname varchar(10) not null comment '名称',
13+
dloc varchar(20) not null comment '所在地',
14+
primary key (dno)
1515
);
16-
-- 添加部门记录
17-
insert into TbDept values (10, '会计部', '北京');
18-
insert into TbDept values (20, '研发部', '成都');
19-
insert into TbDept values (30, '销售部', '重庆');
20-
insert into TbDept values (40, '运维部', '深圳');
21-
-- 创建员工表
22-
create table TbEmp
16+
17+
insert into tb_dept values
18+
(10, '会计部', '北京'),
19+
(20, '研发部', '成都'),
20+
(30, '销售部', '重庆'),
21+
(40, '运维部', '深圳');
22+
23+
create table tb_emp
2324
(
24-
empno int primary key, -- 员工编号
25-
ename varchar(20) not null, -- 员工姓名
26-
job varchar(20) not null, -- 员工职位
27-
mgr int, -- 主管编号
28-
sal int not null, -- 员工月薪
29-
comm int, -- 每月补贴
30-
dno tinyint -- 所在部门编号
25+
eno int not null comment '员工编号',
26+
ename varchar(20) not null comment '员工姓名',
27+
job varchar(20) not null comment '员工职位',
28+
mgr int comment '主管编号',
29+
sal int not null comment '员工月薪',
30+
comm int comment '每月补贴',
31+
dno int comment '所在部门编号',
32+
primary key (eno)
3133
);
32-
-- 添加外键约束
33-
alter table TbEmp add constraint fk_dno foreign key (dno) references TbDept(deptno);
34-
-- 添加员工记录
35-
insert into TbEmp values (7800, '张三丰', '总裁', null, 9000, 1200, 20);
36-
insert into TbEmp values (2056, '乔峰', '分析师', 7800, 5000, 1500, 20);
37-
insert into TbEmp values (3088, '李莫愁', '设计师', 2056, 3500, 800, 20);
38-
insert into TbEmp values (3211, '张无忌', '程序员', 2056, 3200, null, 20);
39-
insert into TbEmp values (3233, '丘处机', '程序员', 2056, 3400, null, 20);
40-
insert into TbEmp values (3251, '张翠山', '程序员', 2056, 4000, null, 20);
41-
insert into TbEmp values (5566, '宋远桥', '会计师', 7800, 4000, 1000, 10);
42-
insert into TbEmp values (5234, '郭靖', '出纳', 5566, 2000, null, 10);
43-
insert into TbEmp values (3344, '黄蓉', '销售主管', 7800, 3000, 800, 30);
44-
insert into TbEmp values (1359, '胡一刀', '销售员', 3344, 1800, 200, 30);
45-
insert into TbEmp values (4466, '苗人凤', '销售员', 3344, 2500, null, 30);
46-
insert into TbEmp values (3244, '欧阳锋', '程序员', 3088, 3200, null, 20);
47-
insert into TbEmp values (3577, '杨过', '会计', 5566, 2200, null, 10);
48-
insert into TbEmp values (3588, '朱九真', '会计', 5566, 2500, null, 10);
34+
35+
alter table tb_emp add constraint fk_emp_dno foreign key (dno) references tb_dept (dno);
36+
37+
insert into tb_emp values
38+
(7800, '张三丰', '总裁', null, 9000, 1200, 20),
39+
(2056, '乔峰', '分析师', 7800, 5000, 1500, 20),
40+
(3088, '李莫愁', '设计师', 2056, 3500, 800, 20),
41+
(3211, '张无忌', '程序员', 2056, 3200, null, 20),
42+
(3233, '丘处机', '程序员', 2056, 3400, null, 20),
43+
(3251, '张翠山', '程序员', 2056, 4000, null, 20),
44+
(5566, '宋远桥', '会计师', 7800, 4000, 1000, 10),
45+
(5234, '郭靖', '出纳', 5566, 2000, null, 10),
46+
(3344, '黄蓉', '销售主管', 7800, 3000, 800, 30),
47+
(1359, '胡一刀', '销售员', 3344, 1800, 200, 30),
48+
(4466, '苗人凤', '销售员', 3344, 2500, null, 30),
49+
(3244, '欧阳锋', '程序员', 3088, 3200, null, 20),
50+
(3577, '杨过', '会计', 5566, 2200, null, 10),
51+
(3588, '朱九真', '会计', 5566, 2500, null, 10);
52+
4953

5054
-- 查询薪资最高的员工姓名和工资
5155

@@ -67,22 +71,22 @@ insert into TbEmp values (3588, '朱九真', '会计', 5566, 2500, null, 10);
6771

6872
-- 查询薪资排名4~6名的员工姓名和工资
6973

70-
use HRS;
74+
-- use hrs;
7175

72-
drop procedure if exists sp_avg_sal_by_dept;
76+
-- drop procedure if exists sp_avg_sal_by_dept;
7377

7478

75-
create procedure sp_avg_sal_by_dept(deptno integer, out avg_sal float)
76-
begin
77-
select avg(sal) into avg_sal from TbEmp where dno=deptno;
78-
end;
79+
-- create procedure sp_avg_sal_by_dept(dno integer, out avg_sal float)
80+
-- begin
81+
-- select avg(sal) into avg_sal from tb_emp where dno=dno;
82+
-- end;
7983

8084

8185

8286

83-
call sp_avg_sal_by_dept(10, @avgSal);
87+
-- call sp_avg_sal_by_dept(10, @avgSal);
8488

85-
select @avgSal;
89+
-- select @avgSal;
8690

8791

8892

0 commit comments

Comments
 (0)