forked from varas7/inventory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinventory_db.sql
64 lines (57 loc) · 1.48 KB
/
inventory_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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
CREATE TABLE product (
product_id int NOT NULL AUTO_INCREMENT,
product_name varchar(50) NOT NULL,
category varchar(20) NOT NULL,
qty int NOT NULL,
cp int NOT NULL,
sp int NOT NULL,
exp_date date NOT NULL,
buy_ts timestamp NOT NULL,
PRIMARY KEY(product_id, product_name, cp, exp_date)
);
CREATE TABLE roles (
username varchar(15),
password varchar(32),
role varchar(15)
);
CREATE TABLE mfg_company (
product_name varchar(50) references product(product_name),
company varchar(50) NOT NULL,
PRIMARY KEY(product_name, company)
);
CREATE TABLE category (
product_name varchar(50) references product(product_name),
category varchar(50) NOT NULL,
PRIMARY KEY(product_name, category)
);
CREATE TABLE transaction (
id int PRIMARY KEY NOT NULL AUTO_INCREMENT,
txn_timestamp timestamp NOT NULL,
txn_type char(1) NOT NULL
);
CREATE TABLE person (
pid int PRIMARY KEY NOT NULL AUTO_INCREMENT,
name varchar(60) NOT NULL,
username varchar(20) NOT NULL,
address text NOT NULL,
contact_no int NOT NULL,
role char(10)
);
CREATE TABLE txn_on (
product_name varchar(60) NOT NULL,
txn_timestamp timestamp NOT NULL,
expiry_date date NOT NULL,
cp int NOT NULL,
id int NOT NULL,
qty_buy_sell int NOT NULL,
txn_type char(1) NOT NULL,
PRIMARY KEY(product_name, txn_timestamp, expiry_date, cp,
id),
FOREIGN KEY(id) REFERENCES transaction(id)
);
CREATE TABLE txn_person (
id int NOT NULL,
pid_person int NOT NULL,
PRIMARY KEY(id, pid_person),
FOREIGN KEY(id) REFERENCES transaction(id)
);