-
Notifications
You must be signed in to change notification settings - Fork 0
/
QuickDBD-export.sql
82 lines (68 loc) · 2.23 KB
/
QuickDBD-export.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
70
71
72
73
74
75
76
77
78
79
80
81
-- Exported from QuickDBD: https://www.quickdatabasediagrams.com/
-- NOTE! If you have used non-SQL datatypes in your design, you will have to change these here.
CREATE TABLE "Departments" (
"dept_no" varchar NOT NULL,
"dept_name" varchar NOT NULL,
CONSTRAINT "pk_Departments" PRIMARY KEY (
"dept_no"
)
);
CREATE TABLE "Dept_emp" (
"emp_no" int NOT NULL,
"dept_no" varchar NOT NULL,
"from_date" date NOT NULL,
"to_date" date NOT NULL,
CONSTRAINT "pk_Dept_emp" PRIMARY KEY (
"emp_no","dept_no"
)
);
CREATE TABLE "Dept_manager" (
"dept_no" varchar NOT NULL,
"emp_no" int NOT NULL,
"from_date" date NOT NULL,
"to_date" date NOT NULL,
CONSTRAINT "pk_Dept_manager" PRIMARY KEY (
"dept_no","emp_no"
)
);
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,
CONSTRAINT "pk_Employees" PRIMARY KEY (
"emp_no"
)
);
CREATE TABLE "salaries" (
"emp_no" int NOT NULL,
"salary" varchar NOT NULL,
"from_date" date NOT NULL,
"to_date" date NOT NULL,
CONSTRAINT "pk_salaries" PRIMARY KEY (
"emp_no"
)
);
CREATE TABLE "titles" (
"emp_no" int NOT NULL,
"title" varchar NOT NULL,
"from_date" date NOT NULL,
"to_date" date NOT NULL,
CONSTRAINT "pk_titles" PRIMARY KEY (
"emp_no"
)
);
ALTER TABLE "Dept_emp" ADD CONSTRAINT "fk_Dept_emp_dept_no" FOREIGN KEY("dept_no")
REFERENCES "Departments" ("dept_no");
ALTER TABLE "Dept_manager" ADD CONSTRAINT "fk_Dept_manager_dept_no" FOREIGN KEY("dept_no")
REFERENCES "Departments" ("dept_no");
ALTER TABLE "Dept_manager" ADD CONSTRAINT "fk_Dept_manager_emp_no" FOREIGN KEY("emp_no")
REFERENCES "Employees" ("emp_no");
ALTER TABLE "Employees" ADD CONSTRAINT "fk_Employees_emp_no" FOREIGN KEY("emp_no")
REFERENCES "Dept_emp" ("emp_no");
ALTER TABLE "salaries" ADD CONSTRAINT "fk_salaries_emp_no" FOREIGN KEY("emp_no")
REFERENCES "Employees" ("emp_no");
ALTER TABLE "titles" ADD CONSTRAINT "fk_titles_emp_no" FOREIGN KEY("emp_no")
REFERENCES "Employees" ("emp_no");