-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_table_schema.sql
54 lines (40 loc) · 1.08 KB
/
create_table_schema.sql
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
ALTER DATABASE sql_challenge
SET datestyle TO "ISO, MDY";
CREATE TABLE titles(
title_id VARCHAR(20) NOT NULL,
title VARCHAR(30) NOT NULL,
PRIMARY KEY (title_id)
);
CREATE TABLE departments(
dept_no VARCHAR(10) NOT NULL,
dept_name VARCHAR(20) NOT NULL,
PRIMARY KEY (dept_no)
);
CREATE TABLE employees(
emp_no INT NOT NULL,
emp_title_id VARCHAR(20) NOT NULL,
birth_date DATE NOT NULL,
first_name VARCHAR(30) NOT NULL,
last_name VARCHAR(30) NOT NULL,
sex VARCHAR(1) NOT NULL,
hire_date DATE NOT NULL,
FOREIGN KEY (emp_title_id) REFERENCES titles(title_id),
PRIMARY KEY(emp_no));
CREATE TABLE dept_emp(
emp_no INT NOT NULL,
FOREIGN KEY (emp_no) REFERENCES employees(emp_no),
dept_no VARCHAR(10) NOT NULL,
FOREIGN KEY (dept_no) REFERENCES departments(dept_no)
);
CREATE TABLE dept_manager(
dept_no VARCHAR(10) NOT NULL,
FOREIGN KEY (dept_no) REFERENCES departments(dept_no),
emp_no INT NOT NULL,
FOREIGN KEY (emp_no) REFERENCES employees(emp_no),
PRIMARY KEY (dept_no,emp_no)
);
CREATE TABLE salaries(
emp_no INT NOT NULL,
salary INT NOT NULL,
FOREIGN KEY(emp_no) REFERENCES employees(emp_no)
);