-
Notifications
You must be signed in to change notification settings - Fork 0
/
project.sql
88 lines (62 loc) · 2.16 KB
/
project.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
82
83
84
85
86
DROP SCHEMA IF EXISTS OrderProcessingSystem;
CREATE SCHEMA OrderProcessingSystem;
USE OrderProcessingSystem;
CREATE TABLE `BOOK` (
`ISBN` VARCHAR(100) NOT NULL,
`Title` VARCHAR(200) NOT NULL,
`PID` INT NOT NULL,
`Year` DATE NULL,
`Price` DOUBLE NOT NULL,
`Category` VARCHAR(200),
`Threshold` INT(15) NOT NULL,
`Stock` INT(15) NOT NULL DEFAULT '0',
PRIMARY KEY (`ISBN`)
);
CREATE INDEX book_title ON BOOK(Title);
CREATE INDEX book_category ON BOOK(Category);
CREATE TABLE `USER` (
`ID` INT(15) NOT NULL AUTO_INCREMENT,
`Name` VARCHAR(200) NOT NULL UNIQUE,
`FName` VARCHAR(200) NOT NULL,
`LName` VARCHAR(200) NOT NULL,
`password` VARCHAR(200) NOT NULL,
`Email` VARCHAR(200) NOT NULL UNIQUE,
`PhoneNumber` varchar(15) DEFAULT NULL,
`ShippingAddress` VARCHAR(200) NULL,
`IsManager` tinyint(1) DEFAULT '0',
PRIMARY KEY (`ID`)
);
CREATE TABLE `BOOK_AUTHORS` (
`ISBN` VARCHAR(100) NOT NULL,
`AuthorName` VARCHAR(100) NOT NULL,
PRIMARY KEY (`ISBN` ,`AuthorName`)
);
CREATE TABLE `BOOK_PUBLISHER` (
`PID` INT(15) NOT NULL AUTO_INCREMENT,
`FName` VARCHAR(100) NOT NULL,
`LName` VARCHAR(100) NOT NULL,
`Address` VARCHAR(100),
`Phone` VARCHAR(100) NULL,
`Email` VARCHAR(100) NULL,
PRIMARY KEY (`PID`)
);
CREATE TABLE `BOOK_ORDERS` (
`OrderId` INT(15) NOT NULL,
`ISBN` VARCHAR(100) NOT NULL,
`Quantity` INT(15) NOT NULL,
PRIMARY KEY (`ISBN`)
);
CREATE TABLE `BOOKS_SOLD` (
`UID` INT(15) NOT NULL,
`ISBN` VARCHAR(100) NOT NULL,
`SellingDate` Date NOT NULL,
`SellingTime` time NULL,
`Price` Double NOT NULL,
`Quantity` INT(15) NOT NULL,
PRIMARY KEY (`ISBN` , `UID`)
);
ALTER TABLE BOOK ADD FOREIGN KEY (`PID`) REFERENCES `BOOK_PUBLISHER`(`PID`) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE BOOK_AUTHORS ADD FOREIGN KEY(`ISBN`) REFERENCES `BOOK`(`ISBN`) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE BOOK_ORDERS ADD FOREIGN KEY (`ISBN`) REFERENCES `BOOK`(`ISBN`) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE BOOKS_SOLD ADD FOREIGN KEY (`ISBN`) REFERENCES `BOOK`(`ISBN`) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE BOOKS_SOLD ADD FOREIGN KEY (`UID`) REFERENCES `USER`(`ID`) ON DELETE CASCADE ON UPDATE CASCADE;