Skip to content

Commit 49d3da0

Browse files
committed
populate new DB
1 parent 0a4a28b commit 49d3da0

20 files changed

+3920157
-1
lines changed

README.md

+110-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,110 @@
1-
# BackUp_SQL_dumps
1+
# test_db
2+
A sample database with an integrated test suite, used to test your applications and database servers
3+
4+
## Where it comes from
5+
6+
The original data was created by Fusheng Wang and Carlo Zaniolo at
7+
Siemens Corporate Research. The data is in XML format.
8+
http://timecenter.cs.aau.dk/software.htm
9+
10+
Giuseppe Maxia made the relational schema and Patrick Crews exported
11+
the data in relational format.
12+
13+
The database contains about 300,000 employee records with 2.8 million
14+
salary entries. The export data is 167 MB, which is not huge, but
15+
heavy enough to be non-trivial for testing.
16+
17+
The data was generated, and as such there are inconsistencies and subtle
18+
problems. Rather than removing them, we decided to leave the contents
19+
untouched, and use these issues as data cleaning exercises.
20+
21+
## Prerequisites
22+
23+
You need a MySQL database server (5.0+) and run the commands below through a
24+
user that has the following privileges:
25+
26+
SELECT, INSERT, UPDATE, DELETE,
27+
CREATE, DROP, RELOAD, REFERENCES,
28+
INDEX, ALTER, SHOW DATABASES,
29+
CREATE TEMPORARY TABLES,
30+
LOCK TABLES, EXECUTE, CREATE VIEW
31+
32+
## Installation:
33+
34+
1. Download the repository
35+
2. Change directory to the repository
36+
37+
Then run
38+
39+
mysql < employees.sql
40+
41+
42+
If you want to install with two large partitioned tables, run
43+
44+
mysql < employees_partitioned.sql
45+
46+
47+
## Testing the installation
48+
49+
After installing, you can run one of the following
50+
51+
mysql -t < test_employees_md5.sql
52+
# OR
53+
mysql -t < test_employees_sha.sql
54+
55+
For example:
56+
57+
mysql -t < test_employees_md5.sql
58+
+----------------------+
59+
| INFO |
60+
+----------------------+
61+
| TESTING INSTALLATION |
62+
+----------------------+
63+
+--------------+------------------+----------------------------------+
64+
| table_name | expected_records | expected_crc |
65+
+--------------+------------------+----------------------------------+
66+
| employees | 300024 | 4ec56ab5ba37218d187cf6ab09ce1aa1 |
67+
| departments | 9 | d1af5e170d2d1591d776d5638d71fc5f |
68+
| dept_manager | 24 | 8720e2f0853ac9096b689c14664f847e |
69+
| dept_emp | 331603 | ccf6fe516f990bdaa49713fc478701b7 |
70+
| titles | 443308 | bfa016c472df68e70a03facafa1bc0a8 |
71+
| salaries | 2844047 | fd220654e95aea1b169624ffe3fca934 |
72+
+--------------+------------------+----------------------------------+
73+
+--------------+------------------+----------------------------------+
74+
| table_name | found_records | found_crc |
75+
+--------------+------------------+----------------------------------+
76+
| employees | 300024 | 4ec56ab5ba37218d187cf6ab09ce1aa1 |
77+
| departments | 9 | d1af5e170d2d1591d776d5638d71fc5f |
78+
| dept_manager | 24 | 8720e2f0853ac9096b689c14664f847e |
79+
| dept_emp | 331603 | ccf6fe516f990bdaa49713fc478701b7 |
80+
| titles | 443308 | bfa016c472df68e70a03facafa1bc0a8 |
81+
| salaries | 2844047 | fd220654e95aea1b169624ffe3fca934 |
82+
+--------------+------------------+----------------------------------+
83+
+--------------+---------------+-----------+
84+
| table_name | records_match | crc_match |
85+
+--------------+---------------+-----------+
86+
| employees | OK | ok |
87+
| departments | OK | ok |
88+
| dept_manager | OK | ok |
89+
| dept_emp | OK | ok |
90+
| titles | OK | ok |
91+
| salaries | OK | ok |
92+
+--------------+---------------+-----------+
93+
94+
95+
## DISCLAIMER
96+
97+
To the best of my knowledge, this data is fabricated and
98+
it does not correspond to real people.
99+
Any similarity to existing people is purely coincidental.
100+
101+
102+
## LICENSE
103+
This work is licensed under the
104+
Creative Commons Attribution-Share Alike 3.0 Unported License.
105+
To view a copy of this license, visit
106+
http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to
107+
Creative Commons, 171 Second Street, Suite 300, San Francisco,
108+
California, 94105, USA.
109+
110+

employees.sql

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
-- Sample employee database
2+
--
3+
-- This work is licensed under the
4+
-- Creative Commons Attribution-Share Alike 3.0 Unported License.
5+
-- To view a copy of this license, visit
6+
-- http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to
7+
-- Creative Commons, 171 Second Street, Suite 300, San Francisco,
8+
-- California, 94105, USA.
9+
--
10+
-- DISCLAIMER
11+
-- To the best of our knowledge, this data is fabricated, and
12+
-- it does not correspond to real people.
13+
-- Any similarity to existing people is purely coincidental.
14+
--
15+
16+
DROP DATABASE IF EXISTS employees;
17+
CREATE DATABASE IF NOT EXISTS employees;
18+
USE employees;
19+
20+
SELECT 'CREATING DATABASE STRUCTURE' as 'INFO';
21+
22+
DROP TABLE IF EXISTS dept_emp,
23+
dept_manager,
24+
titles,
25+
salaries,
26+
employees,
27+
departments;
28+
29+
/*!50503 set default_storage_engine = InnoDB */;
30+
/*!50503 select CONCAT('storage engine: ', @@default_storage_engine) as INFO */;
31+
32+
CREATE TABLE employees (
33+
emp_no INT NOT NULL,
34+
birth_date DATE NOT NULL,
35+
first_name VARCHAR(14) NOT NULL,
36+
last_name VARCHAR(16) NOT NULL,
37+
gender ENUM ('M','F') NOT NULL,
38+
hire_date DATE NOT NULL,
39+
PRIMARY KEY (emp_no)
40+
);
41+
42+
CREATE TABLE departments (
43+
dept_no CHAR(4) NOT NULL,
44+
dept_name VARCHAR(40) NOT NULL,
45+
PRIMARY KEY (dept_no),
46+
UNIQUE KEY (dept_name)
47+
);
48+
49+
CREATE TABLE dept_manager (
50+
emp_no INT NOT NULL,
51+
dept_no CHAR(4) NOT NULL,
52+
from_date DATE NOT NULL,
53+
to_date DATE NOT NULL,
54+
FOREIGN KEY (emp_no) REFERENCES employees (emp_no) ON DELETE CASCADE,
55+
FOREIGN KEY (dept_no) REFERENCES departments (dept_no) ON DELETE CASCADE,
56+
PRIMARY KEY (emp_no,dept_no)
57+
);
58+
59+
CREATE TABLE dept_emp (
60+
emp_no INT NOT NULL,
61+
dept_no CHAR(4) NOT NULL,
62+
from_date DATE NOT NULL,
63+
to_date DATE NOT NULL,
64+
FOREIGN KEY (emp_no) REFERENCES employees (emp_no) ON DELETE CASCADE,
65+
FOREIGN KEY (dept_no) REFERENCES departments (dept_no) ON DELETE CASCADE,
66+
PRIMARY KEY (emp_no,dept_no)
67+
);
68+
69+
CREATE TABLE titles (
70+
emp_no INT NOT NULL,
71+
title VARCHAR(50) NOT NULL,
72+
from_date DATE NOT NULL,
73+
to_date DATE,
74+
FOREIGN KEY (emp_no) REFERENCES employees (emp_no) ON DELETE CASCADE,
75+
PRIMARY KEY (emp_no,title, from_date)
76+
)
77+
;
78+
79+
CREATE TABLE salaries (
80+
emp_no INT NOT NULL,
81+
salary INT NOT NULL,
82+
from_date DATE NOT NULL,
83+
to_date DATE NOT NULL,
84+
FOREIGN KEY (emp_no) REFERENCES employees (emp_no) ON DELETE CASCADE,
85+
PRIMARY KEY (emp_no, from_date)
86+
)
87+
;
88+
89+
CREATE OR REPLACE VIEW dept_emp_latest_date AS
90+
SELECT emp_no, MAX(from_date) AS from_date, MAX(to_date) AS to_date
91+
FROM dept_emp
92+
GROUP BY emp_no;
93+
94+
# shows only the current department for each employee
95+
CREATE OR REPLACE VIEW current_dept_emp AS
96+
SELECT l.emp_no, dept_no, l.from_date, l.to_date
97+
FROM dept_emp d
98+
INNER JOIN dept_emp_latest_date l
99+
ON d.emp_no=l.emp_no AND d.from_date=l.from_date AND l.to_date = d.to_date;
100+
101+
flush /*!50503 binary */ logs;
102+
103+
SELECT 'LOADING departments' as 'INFO';
104+
source load_departments.dump ;
105+
SELECT 'LOADING employees' as 'INFO';
106+
source load_employees.dump ;
107+
SELECT 'LOADING dept_emp' as 'INFO';
108+
source load_dept_emp.dump ;
109+
SELECT 'LOADING dept_manager' as 'INFO';
110+
source load_dept_manager.dump ;
111+
SELECT 'LOADING titles' as 'INFO';
112+
source load_titles.dump ;
113+
SELECT 'LOADING salaries' as 'INFO';
114+
source load_salaries1.dump ;
115+
source load_salaries2.dump ;
116+
source load_salaries3.dump ;
117+
118+
source show_elapsed.sql ;

employees_partitioned.sql

+168
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
-- Sample employee database
2+
--
3+
-- This work is licensed under the
4+
-- Creative Commons Attribution-Share Alike 3.0 Unported License.
5+
-- To view a copy of this license, visit
6+
-- http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to
7+
-- Creative Commons, 171 Second Street, Suite 300, San Francisco,
8+
-- California, 94105, USA.
9+
--
10+
-- DISCLAIMER
11+
-- To the best of our knowledge, this data is fabricated, and
12+
-- it does not correspond to real people.
13+
-- Any similarity to existing people is purely coincidental.
14+
--
15+
16+
DROP DATABASE IF EXISTS employees;
17+
CREATE DATABASE IF NOT EXISTS employees;
18+
USE employees;
19+
20+
SELECT 'CREATING DATABASE STRUCTURE' as 'INFO';
21+
22+
DROP TABLE IF EXISTS dept_emp,
23+
dept_manager,
24+
titles,
25+
salaries,
26+
employees,
27+
departments;
28+
29+
/*!50503 set default_storage_engine = InnoDB */;
30+
/*!50503 select CONCAT('storage engine: ', @@default_storage_engine) as INFO */;
31+
32+
CREATE TABLE employees (
33+
emp_no INT NOT NULL,
34+
birth_date DATE NOT NULL,
35+
first_name VARCHAR(14) NOT NULL,
36+
last_name VARCHAR(16) NOT NULL,
37+
gender ENUM ('M','F') NOT NULL,
38+
hire_date DATE NOT NULL,
39+
PRIMARY KEY (emp_no)
40+
);
41+
42+
CREATE TABLE departments (
43+
dept_no CHAR(4) NOT NULL,
44+
dept_name VARCHAR(40) NOT NULL,
45+
PRIMARY KEY (dept_no),
46+
UNIQUE KEY (dept_name)
47+
);
48+
49+
CREATE TABLE dept_manager (
50+
emp_no INT NOT NULL,
51+
dept_no CHAR(4) NOT NULL,
52+
from_date DATE NOT NULL,
53+
to_date DATE NOT NULL,
54+
FOREIGN KEY (emp_no) REFERENCES employees (emp_no) ON DELETE CASCADE,
55+
FOREIGN KEY (dept_no) REFERENCES departments (dept_no) ON DELETE CASCADE,
56+
PRIMARY KEY (emp_no,dept_no)
57+
);
58+
59+
CREATE TABLE dept_emp (
60+
emp_no INT NOT NULL,
61+
dept_no CHAR(4) NOT NULL,
62+
from_date DATE NOT NULL,
63+
to_date DATE NOT NULL,
64+
FOREIGN KEY (emp_no) REFERENCES employees (emp_no) ON DELETE CASCADE,
65+
FOREIGN KEY (dept_no) REFERENCES departments (dept_no) ON DELETE CASCADE,
66+
PRIMARY KEY (emp_no,dept_no)
67+
);
68+
69+
CREATE TABLE titles (
70+
emp_no INT NOT NULL,
71+
title VARCHAR(50) NOT NULL,
72+
from_date DATE NOT NULL,
73+
to_date DATE,
74+
# FOREIGN KEY (emp_no) REFERENCES employees (emp_no) ON DELETE CASCADE,
75+
PRIMARY KEY (emp_no,title, from_date)
76+
);
77+
78+
/*!50510
79+
ALTER TABLE titles
80+
partition by range COLUMNS (from_date)
81+
(
82+
partition p01 values less than ('1985-12-31'),
83+
partition p02 values less than ('1986-12-31'),
84+
partition p03 values less than ('1987-12-31'),
85+
partition p04 values less than ('1988-12-31'),
86+
partition p05 values less than ('1989-12-31'),
87+
partition p06 values less than ('1990-12-31'),
88+
partition p07 values less than ('1991-12-31'),
89+
partition p08 values less than ('1992-12-31'),
90+
partition p09 values less than ('1993-12-31'),
91+
partition p10 values less than ('1994-12-31'),
92+
partition p11 values less than ('1995-12-31'),
93+
partition p12 values less than ('1996-12-31'),
94+
partition p13 values less than ('1997-12-31'),
95+
partition p14 values less than ('1998-12-31'),
96+
partition p15 values less than ('1999-12-31'),
97+
partition p16 values less than ('2000-12-31'),
98+
partition p17 values less than ('2001-12-31'),
99+
partition p18 values less than ('2002-12-31'),
100+
partition p19 values less than (MAXVALUE)
101+
)
102+
*/;
103+
104+
CREATE TABLE salaries (
105+
emp_no INT NOT NULL,
106+
salary INT NOT NULL,
107+
from_date DATE NOT NULL,
108+
to_date DATE NOT NULL,
109+
# FOREIGN KEY (emp_no) REFERENCES employees (emp_no) ON DELETE CASCADE,
110+
PRIMARY KEY (emp_no, from_date)
111+
);
112+
113+
/*!50510
114+
ALTER TABLE salaries
115+
partition by range COLUMNS (from_date)
116+
(
117+
partition p01 values less than ('1985-12-31'),
118+
partition p02 values less than ('1986-12-31'),
119+
partition p03 values less than ('1987-12-31'),
120+
partition p04 values less than ('1988-12-31'),
121+
partition p05 values less than ('1989-12-31'),
122+
partition p06 values less than ('1990-12-31'),
123+
partition p07 values less than ('1991-12-31'),
124+
partition p08 values less than ('1992-12-31'),
125+
partition p09 values less than ('1993-12-31'),
126+
partition p10 values less than ('1994-12-31'),
127+
partition p11 values less than ('1995-12-31'),
128+
partition p12 values less than ('1996-12-31'),
129+
partition p13 values less than ('1997-12-31'),
130+
partition p14 values less than ('1998-12-31'),
131+
partition p15 values less than ('1999-12-31'),
132+
partition p16 values less than ('2000-12-31'),
133+
partition p17 values less than ('2001-12-31'),
134+
partition p18 values less than ('2002-12-31'),
135+
partition p19 values less than (MAXVALUE)
136+
)
137+
*/;
138+
139+
CREATE OR REPLACE VIEW dept_emp_latest_date AS
140+
SELECT emp_no, MAX(from_date) AS from_date, MAX(to_date) AS to_date
141+
FROM dept_emp
142+
GROUP BY emp_no;
143+
144+
# shows only the current department for each employee
145+
CREATE OR REPLACE VIEW current_dept_emp AS
146+
SELECT l.emp_no, dept_no, l.from_date, l.to_date
147+
FROM dept_emp d
148+
INNER JOIN dept_emp_latest_date l
149+
ON d.emp_no=l.emp_no AND d.from_date=l.from_date AND l.to_date = d.to_date;
150+
151+
flush /*!50503 binary */ logs;
152+
153+
SELECT 'LOADING departments' as 'INFO';
154+
source load_departments.dump ;
155+
SELECT 'LOADING employees' as 'INFO';
156+
source load_employees.dump ;
157+
SELECT 'LOADING dept_emp' as 'INFO';
158+
source load_dept_emp.dump ;
159+
SELECT 'LOADING dept_manager' as 'INFO';
160+
source load_dept_manager.dump ;
161+
SELECT 'LOADING titles' as 'INFO';
162+
source load_titles.dump ;
163+
SELECT 'LOADING salaries' as 'INFO';
164+
source load_salaries1.dump ;
165+
source load_salaries2.dump ;
166+
source load_salaries3.dump ;
167+
168+
source show_elapsed.sql ;

0 commit comments

Comments
 (0)