-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcar rental.sql
94 lines (76 loc) · 2.91 KB
/
car rental.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
87
88
89
90
91
92
93
94
/* Car Rental Database */
/* Vehicle */
CREATE TABLE Vehicle (
vehicleNumber CHAR(7), -- including the dash in the number plate.
makeAndModel VARCHAR(100),
engineNumber CHAR(10),
chassisNumber CHAR(6),
fuelType VARCHAR(10),
CONSTRAINT vehiclePk PRIMARY KEY (vehicleNumber),
CONSTRAINT checkFuelType CHECK (fuelType = 'petrol' OR fuelType = 'diesel')
);
/* Rate */
CREATE TABLE Rate (
vehicleNumber CHAR(7),
dailyRate DOUBLE NOT NULL,
weeklyRate DOUBLE NOT NULL,
monthlyRate DOUBLE NOT NULL,
allowedKmPerDay DOUBLE NOT NULL,
costPerExtraKm DOUBLE NOT NULL,
CONSTRAINT ratePk PRIMARY KEY (vehicleNumber),
CONSTRAINT rateVehicleFk FOREIGN KEY (vehicleNumber) REFERENCES Vehicle(vehicleNumber)
);
/* Constraint */
CREATE TABLE Customer (
customerNic CHAR(10), -- 123456789V
licenseNumber CHAR(8) NOT NULL,
customerName VARCHAR(100),
homeAddress VARCHAR(200),
officeAddress VARCHAR(200),
homePhone CHAR(10),
officePhone CHAR(10),
mobilePhone CHAR(10),
CONSTRAINT customerPk PRIMARY KEY (customerNic) ,
CONSTRAINT customerNicCheck CHECK (customerNic LIKE '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][a-zA-Z]'),
CONSTRAINT homePhoneCheck CHECK (homePhone LIKE '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'),
CONSTRAINT officePhoneCheck CHECK (officePhone LIKE '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'),
CONSTRAINT mobilePhoneCheck CHECK (mobilePhone LIKE '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]')
);
/* Rent */
CREATE TABLE Rent (
rentId INT AUTO_INCREMENT,
customerNic CHAR(10), -- 123456789V
startDateTime DATETIME NOT NULL,
endDateTime DATETIME NOT NULL,
duration INT,
deposit DOUBLE,
rentalAmount DOUBLE,
deliveryCharges DOUBLE,
totalAmount DOUBLE,
CONSTRAINT rentPk PRIMARY KEY (rentId, customerNic),
CONSTRAINT rentCustomerFk FOREIGN KEY (customerNic) REFERENCES Customer(customerNic)
);
/* Rent Guarantor */
-- For customers that have to present a guarantor.
CREATE TABLE Guarantor (
rentId INT,
guarantorNic CHAR(10),
guarantorName VARCHAR(100) NOT NULL,
guarantorMobilePhone CHAR(10),
guarantorLandPhone CHAR(10),
guarantorHomeAddress VARCHAR(200),
guarantorOfficeAddress VARCHAR(200),
CONSTRAINT guarantorPk PRIMARY KEY (rentId, guarantorNic),
CONSTRAINT guarantorRentFk FOREIGN KEY (rentId) REFERENCES Rent(rentId),
CONSTRAINT guarantorNicCheck CHECK (guarantorNic LIKE '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][a-zA-Z]'),
CONSTRAINT guarantorMobilePhoneCheck CHECK (guarantorMobilePhone LIKE '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'),
CONSTRAINT guarantorLandPhoneCheck CHECK (guarantorLandPhone LIKE '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]')
);
/* Invoice */
CREATE TABLE Invoice (
invoiceId INT AUTO_INCREMENT,
rentId INT,
totalAmountPaid DOUBLE NOT NULL,
CONSTRAINT invoicePk PRIMARY KEY (invoiceId),
CONSTRAINT invoiceRentFk FOREIGN KEY (rentId) REFERENCES Rent(rentId)
);