-
Notifications
You must be signed in to change notification settings - Fork 0
/
my_db.sql
43 lines (39 loc) · 970 Bytes
/
my_db.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
-- Create the Users table
CREATE TABLE Users (
uid SERIAL PRIMARY KEY,
uname VARCHAR(255) UNIQUE NOT NULL,
upwd VARCHAR(255) NOT NULL
);
-- Create the Products table
CREATE TABLE Products (
pid SERIAL PRIMARY KEY,
pname VARCHAR(255) NOT NULL,
pbrand VARCHAR(255),
pprice DECIMAL,
pcompat VARCHAR(255),
pqty INT,
pcat VARCHAR(255)
);
-- Create the CartItems table
CREATE TABLE CartItems (
cid SERIAL PRIMARY KEY,
uid INT REFERENCES Users(uid),
pid INT REFERENCES Products(pid),
cqty INT
);
-- Create the Orders table
CREATE TABLE Orders (
oid SERIAL PRIMARY KEY,
uid INT REFERENCES Users(uid),
ottd DECIMAL,
delivery_date TIMESTAMPTZ,
created_at TIMESTAMPTZ DEFAULT NOW()
);
-- Create the OrderItems table
CREATE TABLE OrderItems (
id SERIAL PRIMARY KEY,
oid INT REFERENCES Orders(oid),
pid INT REFERENCES Products(pid),
oqty INT,
created_at TIMESTAMPTZ DEFAULT NOW()
);