-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvs_group_erd.sql
60 lines (49 loc) · 1.52 KB
/
vs_group_erd.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
CREATE TABLE `Order` (
`OrderID` varchar(255) PRIMARY KEY,
`OrderDate` datetime,
`CustomerID` varchar(255),
`ProductID` varchar(255),
`Quantity` integer
);
CREATE TABLE `Customer` (
`CustomerID` varchar(255) PRIMARY KEY,
`CustomerName` varchar(255),
`Segment` varchar(255)
);
CREATE TABLE `Product` (
`ProductID` varchar(255) PRIMARY KEY,
`ProductName` varchar(255),
`CataloguePrice` int,
`SupplierPrice` int,
`Category` varchar(255),
`SubCategory` varchar(255)
);
CREATE TABLE `Billing` (
`BillingID` varchar(255) PRIMARY KEY,
`OrderID` varchar(255),
`Sales` int,
`Discount` float,
`Profit` int
);
CREATE TABLE `Shipment` (
`ShipmentID` varchar(255) PRIMARY KEY,
`AddressID` varchar(255),
`OrderID` varchar(255),
`ShipDate` datetime,
`ShipMode` varchar(255)
);
CREATE TABLE `Address` (
`AddressID` varchar(255) PRIMARY KEY,
`CustomerID` varchar(255),
`Country` varchar(255),
`City` varchar(255),
`State` varchar(255),
`PostalCode` integer,
`Region` varchar(255)
);
ALTER TABLE `Order` ADD FOREIGN KEY (`CustomerID`) REFERENCES `Customer` (`CustomerID`);
ALTER TABLE `Order` ADD FOREIGN KEY (`ProductID`) REFERENCES `Product` (`ProductID`);
ALTER TABLE `Shipment` ADD FOREIGN KEY (`OrderID`) REFERENCES `Order` (`OrderID`);
ALTER TABLE `Billing` ADD FOREIGN KEY (`OrderID`) REFERENCES `Order` (`OrderID`);
ALTER TABLE `Address` ADD FOREIGN KEY (`CustomerID`) REFERENCES `Customer` (`CustomerID`);
ALTER TABLE `Shipment` ADD FOREIGN KEY (`AddressID`) REFERENCES `Address` (`AddressID`);