-
Notifications
You must be signed in to change notification settings - Fork 101
/
Copy pathMySQL code
128 lines (105 loc) · 4.1 KB
/
MySQL code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
--THIS CODE WORKS WITH MySQL80 WORKBENCH DESKTOP COMMUNITY VERSION
--------------------------------------------------
-- LinkedIn Learning -----------------------------
-- Advanced SQL: Conquering Relational Division --
-- Ami Levin 2021 --------------------------------
-- HR Demo Database ------------------------------
--------------------------------------------------
-- https://github.com/ami-levin/LinkedIn/tree/master/Relational%20Division/HR%20Demo%20Database
-- DB Fiddle Preloaded with HR Demo Database
-- https://dbfiddle.uk/?rdbms=sqlserver_2019&fiddle=06f6f880236311c73861876be59dc087&hide=1
-- Joe Celko on keys and identifiers:
-- https://www.informationweek.com/software/information-management/celko-on-sql-identifiers-and-the-properties-of-relational-keys/d/d-id/1058284?
-- Fabian Pascal on relational keys:
-- https://www.dbdebunk.com/2018/02/the-key-to-relational-keys-new.html
------------------------
-- Setup (MYSQL80) --
------------------------
DROP DATABASE IF EXISTS hr;
CREATE DATABASE hr;
USE hr;
CREATE TABLE Candidates (
Candidate
VARCHAR(30) NOT NULL
PRIMARY KEY
);
CREATE TABLE Roles (
Role
VARCHAR(30) NOT NULL
PRIMARY KEY
);
CREATE TABLE SkillCategories (
Category
VARCHAR(30) NOT NULL
PRIMARY KEY
);
CREATE TABLE Skills (
Skill
VARCHAR(30) NOT NULL
PRIMARY KEY,
Category
VARCHAR(30) NOT NULL
REFERENCES SkillCategories(Category)
);
CREATE TABLE CandidateSkills (
Candidate
VARCHAR(30) NOT NULL
REFERENCES Candidates(Candidate),
Skill
VARCHAR(30) NOT NULL
REFERENCES Skills(Skill),
PRIMARY KEY (Candidate, Skill)
);
CREATE TABLE RoleSkills (
Role
VARCHAR(30) NOT NULL
REFERENCES Roles(Role),
Skill
VARCHAR(30) NOT NULL
REFERENCES Skills(Skill),
PRIMARY KEY (Role, Skill)
);
INSERT INTO Candidates(Candidate)
VALUES ('Natasha'),('Chen'),('Praveena'),('Kelly'), ('Darrin');
INSERT INTO Roles(Role)
VALUES ('DB Architect'), ('Front End Developer'), ('Office Manager');
INSERT INTO SkillCategories(Category)
VALUES ('Professional'), ('Personal');
INSERT INTO Skills(Skill, Category)
VALUES ('SQL','Professional'), ('DB Design','Professional'), ('C#','Professional'), ('Python','Professional'), ('Java','Professional'), ('Office','Professional'),
('Team Player','Personal'), ('Leader','Personal'), ('Passionate','Personal');
INSERT INTO RoleSkills(Role, Skill)
VALUES ('DB Architect','SQL'), ('DB Architect','DB Design'), ('DB Architect','Python'), ('DB Architect','Team Player'), ('DB Architect','Passionate'),
('Front End Developer','Java'), ('Front End Developer','C#'), ('Front End Developer','Team Player'), ('Front End Developer','Passionate'),
('Office Manager','Passionate'), ('Office Manager','Team Player'), ('Office Manager','Office');
-- Team player and passionate skills are required for all roles
INSERT INTO CandidateSkills(Candidate, Skill)
VALUES ('Natasha','SQL'), ('Natasha','DB Design'), ('Natasha','Team Player'), ('Natasha','Passionate'),
-- Partial match for DB Architect professional, match for personal skills
('Chen','SQL'), ('Chen','DB Design'), ('Chen','Python'), ('Chen','Team Player'), ('Chen','Passionate'),
-- Perfect match for DB Architect
('Praveena','Java'), ('Praveena','C#'), ('Praveena','Team Player'), ('Praveena','Passionate'), ('Praveena','Python'),
-- Over qualified for Front End Developer (has extra skills)
('Kelly','Passionate'), ('Kelly','Leader'),
-- No professional skills
('Darrin','SQL'), ('Darrin','DB Design'), ('Darrin','C#'), ('Darrin','Python'), ('Darrin','Java'), ('Darrin','Office'), ('Darrin','Team Player'), ('Darrin','Leader'), ('Darrin','Passionate');
-- Darrin Has it all
-- And of course, all candidates are passionate...
SELECT *
FROM Skills;
SELECT *
FROM CandidateSkills;
SELECT *
FROM RoleSkills;
-- Cleanup
/*
-- Drop Tables
DROP TABLE CandidateSkills, RoleSkills;
DROP TABLE Skills, Roles;
DROP TABLE SkillCategories, Candidates;
-- Drop Database
USE hr;
DROP DATABASE hr;
*/
---------
-- EOF --