-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTable_creation.sql
More file actions
55 lines (51 loc) · 1.57 KB
/
Table_creation.sql
File metadata and controls
55 lines (51 loc) · 1.57 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
-- Create 'suppliers' first since 'products' references it
CREATE TABLE IF NOT EXISTS PUBLIC.suppliers
(
supplier_id INT PRIMARY KEY,
supplier_name VARCHAR(100),
contact_name VARCHAR(255),
email VARCHAR(255),
phone VARCHAR(100),
address VARCHAR(255)
);
-- Create 'products' next, as it references 'suppliers'
CREATE TABLE IF NOT EXISTS PUBLIC.products
(
product_id INT PRIMARY KEY,
product_name VARCHAR(255),
category VARCHAR(100),
price NUMERIC(10, 2), -- Specified precision and scale
stock_quantity INT,
reorder_level INT,
supplier_id INT,
FOREIGN KEY(supplier_id) REFERENCES public.suppliers (supplier_id)
);
-- The remaining tables reference 'products' or 'suppliers'
CREATE TABLE IF NOT EXISTS PUBLIC.reorders
(
reorder_id INT PRIMARY KEY,
product_id INT,
reorder_quantity INT,
reorder_date DATE,
reorder_status VARCHAR(50), -- Renamed 'status' and used VARCHAR
FOREIGN KEY(product_id) REFERENCES public.products (product_id)
);
CREATE TABLE IF NOT EXISTS PUBLIC.shipments
(
shipment_id INT PRIMARY KEY,
product_id INT,
supplier_id INT,
quantity_received INT,
shipment_date DATE,
FOREIGN KEY(product_id) REFERENCES public.products (product_id),
FOREIGN KEY(supplier_id) REFERENCES public.suppliers (supplier_id)
);
CREATE TABLE IF NOT EXISTS PUBLIC.stock_entries
(
entry_id INT PRIMARY KEY,
product_id INT,
change_quantity NUMERIC,
change_type VARCHAR(50), -- Changed from TEXT
entry_date DATE,
FOREIGN KEY(product_id) REFERENCES public.products (product_id)
);