-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_engineering_tables.sql
69 lines (54 loc) · 1.82 KB
/
data_engineering_tables.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
--Use the information you have and create a table schema for each of the six CSV files. Remember to specify data types, primary keys, foreign keys, and other constraints.
--For the primary keys check if the column is unique, otherwise create a composite key. Which takes to primary keys in order to uniquely identify a row.
--Be sure to create tables in the correct order to handle foreign keys.
--Import each CSV file into the corresponding SQL table. Be sure to import the data in the same order that the tables were created and account for the headers when importing to avoid errors.
CREATE TABLE departments (
dept_no VARCHAR,
dept_name VARCHAR NOT NULL,
PRIMARY KEY (dept_no)
);
select * from departments
CREATE TABLE dept_emp (
emp_no INT NOT NULL,
dept_no VARCHAR NOT NULL,
from_date DATE NOT NULL,
to_date DATE NOT NULL,
FOREIGN KEY (emp_no) REFERENCES employees(emp_no),
FOREIGN KEY (dept_no) REFERENCES departments(dept_no)
);
select * from dept_emp
CREATE TABLE dept_managers (
dept_no VARCHAR,
emp_no INT,
from_date DATE NOT NULL,
to_date DATE NOT NULL,
FOREIGN KEY (dept_no) REFERENCES departments(dept_no),
FOREIGN KEY (emp_no) REFERENCES employees(emp_no)
);
select * from dept_managers
CREATE TABLE employees (
emp_no INT NOT NULL,
birth_date DATE NOT NULL,
first_name VARCHAR NOT NULL,
last_name VARCHAR NOT NULL,
gender VARCHAR NOT NULL,
hire_date DATE NOT NULL,
PRIMARY KEY (emp_no)
);
select * from employees
CREATE TABLE salaries (
emp_no INT NOT NULL,
salary INT NOT NULL,
from_date DATE NOT NULL,
to_date DATE NOT NULL,
FOREIGN KEY(emp_no) REFERENCES employees(emp_no)
);
select * from salaries
CREATE TABLE titles (
emp_no INT NOT NULL,
title VARCHAR NOT NULL,
from_date DATE NOT NULL,
to_date DATE NOT NULL,
FOREIGN KEY(emp_no) REFERENCES employees(emp_no)
);
select * from titles