-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.sql
86 lines (81 loc) · 2.58 KB
/
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
CREATE TABLE
`customer`
(
`id` int unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`dob` date NOT NULL,
`email` varchar(30) NOT NULL,
`phone` char(10) NOT NULL,
`password` varchar(64) NOT NULL,
`gender` varchar(10) NOT NULL,
`district` varchar(20) NOT NULL,
PRIMARY KEY (`id`)
);
CREATE TABLE
`fuel`
(
`id` int unsigned NOT NULL AUTO_INCREMENT,
`type` varchar(50) NOT NULL,
`amount` float NOT NULL,
`price` double NOT NULL,
PRIMARY KEY (`id`),
CONSTRAINT `fuel_amount_check` CHECK ((`amount` >= 0)),
CONSTRAINT `fuel_price_check` CHECK ((`price` > 0))
);
CREATE TABLE
`item`
(
`id` int unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`in_stock` tinyint(1) DEFAULT '1',
PRIMARY KEY (`id`)
);
CREATE TABLE
`staff`
(
`id` int unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`dob` date NOT NULL,
`email` varchar(30) NOT NULL,
`phone` char(10) NOT NULL,
`password` varchar(64) NOT NULL,
`role` int NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
);
CREATE TABLE
`item_request`
(
`id` int unsigned NOT NULL AUTO_INCREMENT,
`item_id` int unsigned DEFAULT NULL,
`staff_id` int unsigned DEFAULT NULL,
`qty` int NOT NULL,
`status` varchar(15) NOT NULL DEFAULT 'Pending',
PRIMARY KEY (`id`),
KEY `req_staff_fk` (`staff_id`),
KEY `req_item_fk` (`item_id`),
CONSTRAINT `req_item_fk` FOREIGN KEY (`item_id`) REFERENCES `item` (`id`) ON DELETE
SET
NULL,
CONSTRAINT `req_staff_fk` FOREIGN KEY (`staff_id`) REFERENCES `staff` (`id`) ON DELETE
SET
NULL,
CONSTRAINT `req_amount_check` CHECK ((`qty` > 0))
);
CREATE TABLE
`appointment`
(
`id` int unsigned NOT NULL AUTO_INCREMENT,
`brand` varchar(50) NOT NULL,
`model` varchar(50) NOT NULL,
`year` varchar(255) NOT NULL,
`type` varchar(50) NOT NULL,
`date` date NOT NULL,
`customer_id` int unsigned NOT NULL,
`status` varchar(50) DEFAULT NULL,
`assigned` int unsigned DEFAULT NULL,
`comment` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `appt_staff_FK` (`assigned`),
CONSTRAINT `appt_cus_FK` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`id`) ON DELETE CASCADE,
CONSTRAINT `appt_staff_FK` FOREIGN KEY (`assigned`) REFERENCES `staff` (`id`) ON DELETE CASCADE
);