forked from fenyx-it-academy/Class7-Database-Module-Week8
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathitcompany.sql
More file actions
74 lines (61 loc) · 1.45 KB
/
Copy pathitcompany.sql
File metadata and controls
74 lines (61 loc) · 1.45 KB
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
BEGIN;
CREATE TABLE IF NOT EXISTS public.customers
(
customer_id integer,
first_name text,
last_name text,
phone integer,
email text,
PRIMARY KEY (customer_id)
);
CREATE TABLE IF NOT EXISTS public.orders
(
order_id integer,
customer_id integer,
product_id integer,
order_date date,
employee_id integer,
PRIMARY KEY (order_id)
);
CREATE TABLE IF NOT EXISTS public.product
(
product_id integer,
name text,
product_statement text,
employee_id integer,
PRIMARY KEY (product_id)
);
CREATE TABLE IF NOT EXISTS public.team
(
employee_id integer,
name text,
phone integer,
email text,
"position" text,
PRIMARY KEY (employee_id)
);
ALTER TABLE IF EXISTS public.orders
ADD FOREIGN KEY (customer_id)
REFERENCES public.customers (customer_id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE IF EXISTS public.orders
ADD FOREIGN KEY (product_id)
REFERENCES public.product (product_id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE IF EXISTS public.orders
ADD FOREIGN KEY (employee_id)
REFERENCES public.team (employee_id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE IF EXISTS public.product
ADD FOREIGN KEY (employee_id)
REFERENCES public.team (employee_id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
END;