CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
DanielBarnes18

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: DanielBarnes18/IBM-Data-Science-Professional-Certificate
Path: blob/main/06. Databases and SQL for Data Science with Python/01. Getting Started with SQL/HR_Database_Create_Tables_Script.sql
Views: 4598
1
------------------------------------------
2
--DDL statement for table 'HR' database--
3
--------------------------------------------
4
5
-- Drop the tables in case they exist
6
7
DROP TABLE EMPLOYEES;
8
DROP TABLE JOB_HISTORY;
9
DROP TABLE JOBS;
10
DROP TABLE DEPARTMENTS;
11
DROP TABLE LOCATIONS;
12
13
-- Create the tables
14
15
CREATE TABLE EMPLOYEES (
16
EMP_ID CHAR(9) NOT NULL,
17
F_NAME VARCHAR(15) NOT NULL,
18
L_NAME VARCHAR(15) NOT NULL,
19
SSN CHAR(9),
20
B_DATE DATE,
21
SEX CHAR,
22
ADDRESS VARCHAR(30),
23
JOB_ID CHAR(9),
24
SALARY DECIMAL(10,2),
25
MANAGER_ID CHAR(9),
26
DEP_ID CHAR(9) NOT NULL,
27
PRIMARY KEY (EMP_ID)
28
);
29
30
CREATE TABLE JOB_HISTORY (
31
EMPL_ID CHAR(9) NOT NULL,
32
START_DATE DATE,
33
JOBS_ID CHAR(9) NOT NULL,
34
DEPT_ID CHAR(9),
35
PRIMARY KEY (EMPL_ID,JOBS_ID)
36
);
37
38
CREATE TABLE JOBS (
39
JOB_IDENT CHAR(9) NOT NULL,
40
JOB_TITLE VARCHAR(15) ,
41
MIN_SALARY DECIMAL(10,2),
42
MAX_SALARY DECIMAL(10,2),
43
PRIMARY KEY (JOB_IDENT)
44
);
45
46
CREATE TABLE DEPARTMENTS (
47
DEPT_ID_DEP CHAR(9) NOT NULL,
48
DEP_NAME VARCHAR(15) ,
49
MANAGER_ID CHAR(9),
50
LOC_ID CHAR(9),
51
PRIMARY KEY (DEPT_ID_DEP)
52
);
53
54
CREATE TABLE LOCATIONS (
55
LOCT_ID CHAR(9) NOT NULL,
56
DEP_ID_LOC CHAR(9) NOT NULL,
57
PRIMARY KEY (LOCT_ID,DEP_ID_LOC)
58
);
59
60