-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb-script.sql
More file actions
130 lines (113 loc) · 4.37 KB
/
db-script.sql
File metadata and controls
130 lines (113 loc) · 4.37 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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
CREATE TABLE `Agent` (
`agentId` varchar(10) NOT NULL,
`agentCode` varchar(15) DEFAULT NULL,
`name` varchar(20) DEFAULT NULL,
`region` varchar(20) DEFAULT NULL,
`territory` varchar(20) DEFAULT NULL,
PRIMARY KEY (`agentId`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `Shop` (
`shopId` varchar(10) NOT NULL,
`name` varchar(30) DEFAULT NULL,
`address` varchar(200) DEFAULT NULL,
`telephone` int(10) DEFAULT NULL,
PRIMARY KEY (`shopId`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `Worker` (
`workerId` varchar(10) NOT NULL,
`name` varchar(30) DEFAULT NULL,
`telephone` int(10) DEFAULT NULL,
`type` varchar(12) DEFAULT NULL,
PRIMARY KEY (`workerId`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `Cement` (
`cementId` varchar(10) NOT NULL,
`name` varchar(10) DEFAULT NULL,
PRIMARY KEY (`cementId`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `CementAgent` (
`cementId` varchar(10) NOT NULL,
`agentId` varchar(10) NOT NULL,
`unitPrice` decimal(6,2) DEFAULT NULL,
PRIMARY KEY (`cementId`,`agentId`),
CONSTRAINT FOREIGN KEY (`cementId`) REFERENCES `Cement` (`cementId`),
CONSTRAINT FOREIGN KEY (`agentId`) REFERENCES `Agent` (`agentId`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `CementShop` (
`cementId` varchar(10) NOT NULL,
`shopId` varchar(10) NOT NULL,
`unitPrice` decimal(6,2) DEFAULT NULL,
PRIMARY KEY (`cementId`,`shopId`),
CONSTRAINT FOREIGN KEY (`cementId`) REFERENCES `Cement` (`cementId`),
CONSTRAINT FOREIGN KEY (`shopId`) REFERENCES `Shop` (`shopId`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `ShopOrder` (
`shopOrderId` varchar(11) NOT NULL,
`shopId` varchar(11) NOT NULL,
`type` varchar(10) DEFAULT NULL,
`oDate` date DEFAULT NULL,
`dDate` date DEFAULT NULL,
`qty` int(10) DEFAULT NULL,
PRIMARY KEY (`shopOrderId`),
CONSTRAINT FOREIGN KEY (`shopId`) REFERENCES `Shop` (`shopId`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `PurchaseOrder` (
`purchaseOrderId` varchar(11) NOT NULL,
`agentId` varchar(11) NOT NULL,
`cementId` varchar(11) NOT NULL,
`oDate` date DEFAULT NULL,
`qty` int(10) DEFAULT NULL,
`chequeNumber` varchar(15) DEFAULT NULL,
`dDate` date DEFAULT NULL,
`amount` decimal(10,2) DEFAULT NULL,
PRIMARY KEY (`purchaseOrderId`),
CONSTRAINT FOREIGN KEY (`agentId`) REFERENCES `Agent` (`agentId`),
CONSTRAINT FOREIGN KEY (`cementId`) REFERENCES `Cement` (`cementId`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `Delivery` (
`deliveryId` varchar(11) NOT NULL,
`purchaseOrderId` varchar(11) NOT NULL,
`type` varchar(10) DEFAULT NULL,
`date` date DEFAULT NULL,
PRIMARY KEY (`deliveryId`),
CONSTRAINT FOREIGN KEY (`purchaseOrderId`) REFERENCES `PurchaseOrder` (`purchaseOrderId`),
CONSTRAINT FOREIGN KEY (`type`) REFERENCES `PurchaseOrder` (`cementId`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `ShopDelivery` (
`deliveryId` varchar(11) NOT NULL,
`shopId` varchar(11) NOT NULL,
`type` varchar(10) DEFAULT NULL,
`date` date DEFAULT NULL,
`qty` int(10) DEFAULT NULL,
PRIMARY KEY (`deliveryId`,`shopId`),
CONSTRAINT FOREIGN KEY (`deliveryId`) REFERENCES `Delivery` (`deliveryId`),
CONSTRAINT FOREIGN KEY (`shopId`) REFERENCES `Shop` (`shopId`),
CONSTRAINT FOREIGN KEY (`type`) REFERENCES `Delivery` (`type`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `ShopPayment` (
`shopPaymentId` varchar(11) NOT NULL,
`shopId` varchar(11) NOT NULL,
`type` varchar(10) DEFAULT NULL,
`date` date DEFAULT NULL,
`amount` decimal(10,2) DEFAULT NULL,
PRIMARY KEY (`shopPaymentId`),
CONSTRAINT FOREIGN KEY (`shopId`) REFERENCES `Shop` (`shopId`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `ChequePayment` (
`chequePaymentId` varchar(11) NOT NULL,
`shopPaymentId` varchar(11) NOT NULL,
`chequeNo` varchar(10) DEFAULT NULL,
`dDate` date DEFAULT NULL,
`amount` decimal(10,2) DEFAULT NULL,
`returned` varchar(10) DEFAULT NULL,
PRIMARY KEY (`chequePaymentId`),
CONSTRAINT FOREIGN KEY (`shopPaymentId`) REFERENCES `ShopPayment` (`shopPaymentId`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `WorkerPayment` (
`workerPaymentId` varchar(11) NOT NULL,
`workerId` varchar(11) NOT NULL,
`date` date DEFAULT NULL,
`amount` decimal(6,2) DEFAULT NULL,
PRIMARY KEY (`workerPaymentId`),
CONSTRAINT FOREIGN KEY (`workerId`) REFERENCES `Worker` (`workerId`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;