--------------------------------------------------------------------------------
/Create_Tables.sql:
--------------------------------------------------------------------------------
1 | CREATE DATABASE CAR_RENTAL;
2 |
3 | USE CAR_RENTAL;
4 |
5 | CREATE TABLE IF NOT EXISTS CAR(
6 | Vehicle_id INT(10) NOT NULL ,
7 | License_no VARCHAR(20),
8 | Model VARCHAR(20),
9 | Year DATE,
10 | Ctype VARCHAR(20),
11 | Drate INT(10),
12 | Wrate INT(10),
13 | Status VARCHAR(20),
14 | PRIMARY KEY (Vehicle_id),
15 | UNIQUE (License_no)
16 | );
17 |
18 | CREATE TABLE IF NOT EXISTS CUSTOMER (
19 | Cid INT(10) NOT NULL ,
20 | Fname VARCHAR(1),
21 | Lname VARCHAR(20),
22 | Mobile INT(12),
23 | Dno INT(10),
24 | Vehicle_id INT(10),
25 | FOREIGN KEY (Dno) REFERENCES DRIVER(Dno) ON UPDATE CASCADE,
26 | FOREIGN KEY (Vehicle_id) REFERENCES CAR(Vehicle_id) ON UPDATE CASCADE,
27 | PRIMARY KEY (Cid)
28 | );
29 |
30 | CREATE TABLE IF NOT EXISTS MEMBERS (
31 | Mid INT(10) NOT NULL ,
32 | Mtype VARCHAR(20),
33 | Discount INT(10),
34 | Duration VARCHAR(10),
35 | Cid INT(10),
36 | PRIMARY KEY (Mid),
37 | FOREIGN KEY (Cid) REFERENCES CUSTOMER(Cid) ON UPDATE CASCADE
38 | );
39 |
40 | CREATE TABLE IF NOT EXISTS CUSTOMER_SERVICE(
41 | Empid INT(10) NOT NULL ,
42 | Name VARCHAR(20),
43 | Mobile INT(12),
44 | PRIMARY KEY (Empid)
45 | );
46 |
47 | CREATE TABLE IF NOT EXISTS FEEDBACK(
48 | Fid INT(10) NOT NULL ,
49 | Message VARCHAR(140),
50 | Email VARCHAR(50),
51 | Empid INT(10),
52 | Cid INT(10),
53 | PRIMARY KEY (Fid),
54 | FOREIGN KEY (Empid) REFERENCES CUSTOMER_SERVICE(Empid) ON UPDATE CASCADE,
55 | FOREIGN KEY (Cid) REFERENCES CUSTOMER(Cid) ON UPDATE CASCADE,
56 | );
57 |
58 | CREATE TABLE IF NOT EXISTS DRIVER(
59 | Dno INT(10) NOT NULL,
60 | PRIMARY KEY (Dno),
61 | );
62 |
63 | CREATE TABLE IF NOT EXISTS SELF (
64 | Dlno INT(10) NOT NULL,
65 | Name VARCHAR(20),
66 | Insurance_no INT(12),
67 | Dno INT(10),
68 | PRIMARY KEY (Dlno),
69 | FOREIGN KEY (Dno) REFERENCES DRIVER(Dno) ON UPDATE CASCADE,
70 | );
71 |
72 | CREATE TABLE IF NOT EXISTS CHAUFFEUR (
73 | Chid INT(10) NOT NULL,
74 | Name VARCHAR(20),
75 | Gender Varchar(10),
76 | Status VARCHAR(20),
77 | Mobile INT(12),
78 | Dno INT(10),
79 | PRIMARY KEY (Chid),
80 | FOREIGN KEY (Dno) REFERENCES DRIVER(Dno) ON UPDATE CASCADE,
81 | );
82 |
83 | CREATE TABLE IF NOT EXISTS RENTAL (
84 | Rid INT(10) NOT NULL ,
85 | Rdate DATE,
86 | Amount INT(10),
87 | Dno INT(10),
88 | Vehicle_id INT(10),
89 | PRIMARY KEY (Rid),
90 | FOREIGN KEY (Vehicle_id) REFERENCES CAR(Vehicle_id) ON UPDATE CASCADE,
91 | FOREIGN KEY (Dno) REFERENCES DRIVER(Dno) ON UPDATE CASCADE,
92 | );
93 |
94 | CREATE TABLE IF NOT EXISTS DAILY (
95 | Rid INT(10) NOT NULL,
96 | Sdate DATE,
97 | Amount INT(10),
98 | Nodays INT(10),
99 | Vehicle_id INT(10),
100 | Dno INT(10),
101 | PRIMARY KEY (Rid),
102 | FOREIGN KEY (Rid) REFERENCES RENTAL(Rid) ON UPDATE CASCADE,
103 | FOREIGN KEY (Vehicle_id) REFERENCES CAR(Vehicle_id) ON UPDATE CASCADE,
104 | FOREIGN KEY (Dno) REFERENCES DRIVER(Dno) ON UPDATE CASCADE,
105 | );
106 |
107 | CREATE TABLE IF NOT EXISTS WEEKLY(
108 | Rid INT(10) NOT NULL,
109 | Sdate DATE,
110 | Amount INT(10),
111 | Noweeks INT(10),
112 | Vehicle_id INT(10),
113 | Dno INT(10),
114 | PRIMARY KEY (Rid),
115 | FOREIGN KEY (Rid) REFERENCES RENTAL(Rid) ON UPDATE CASCADE,
116 | FOREIGN KEY (Vehicle_id) REFERENCES CAR(Vehicle_id) ON UPDATE CASCADE,
117 | FOREIGN KEY (Dno) REFERENCES DRIVER(Dno) ON UPDATE CASCADE
118 | );
119 |
120 | CREATE TABLE IF NOT EXISTS BILL (
121 | Bno INT(10) NOT NULL,
122 | BDate DATE,
123 | Advance INT(10),
124 | Discount INT(10),
125 | Drivercharge INT(10),
126 | Famount INT(10),
127 | Rid INT(10),
128 | Cid INT(10),
129 | PRIMARY KEY (Bno),
130 | FOREIGN KEY (Rid) REFERENCES RENTAL(Rid) ON UPDATE CASCADE,
131 | FOREIGN KEY (Cid) REFERENCES CUSTOMER(Cid) ON UPDATE CASCADE
132 | );
133 |
134 | CREATE TABLE IF NOT EXISTS OWNS (
135 | Owner_id INT(10) NOT NULL,
136 | Vehicle_id INT(10),
137 | PRIMARY KEY (Owner_id),
138 | FOREIGN KEY (Owner_id) REFERENCES OWNER(Owner_id) ON UPDATE CASCADE,
139 | );
140 |
141 | CREATE TABLE IF NOT EXISTS OWNER (
142 | Owner_id INT(10) NOT NULL,
143 | PRIMARY KEY (Owner_id)
144 | );
145 |
146 | CREATE TABLE IF NOT EXISTS INDIVIDUAL (
147 | Ssn INT(10) NOT NULL,
148 | Name VARCHAR(20),
149 | Owner_id INT(10),
150 | PRIMARY KEY (Ssn),
151 | FOREIGN KEY (Owner_id) REFERENCES OWNER(Owner_id) ON UPDATE CASCADE
152 | );
153 |
154 | CREATE TABLE IF NOT EXISTS BANK (
155 | Bid INT(10) NOT NULL,
156 | Bname VARCHAR(20),
157 | City VARCHAR(20),
158 | Owner_id INT(10),
159 | PRIMARY KEY (Bid),
160 | FOREIGN KEY (Owner_id) REFERENCES OWNER(Owner_id) ON UPDATE CASCADE
161 | );
162 |
163 | CREATE TABLE IF NOT EXISTS COMPANY (
164 | Compid INT(10) NOT NULL,
165 | Cname VARCHAR(20),
166 | Owner_id INT(10),
167 | PRIMARY KEY (Compid),
168 | FOREIGN KEY (Owner_id) REFERENCES OWNER(Owner_id) ON UPDATE CASCADE
169 | );
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ##Online Car Rental System##
2 | **Database Systems Project**
3 |
4 | Technologies: MySQL, PHP, HTML and CSS
5 |
6 | Design and implement a database for keeping track of information about a car rental company.
7 |
8 | Following tasks were achieved:
9 |
10 | The following are the tasks for the third part of the project:
11 |
12 | 1. Load some initial data (as discussed above) into the database tables. You can either write a loading program, or use SQL/PLUS (insert command), or use SQL/FORMS. Your data should be kept in files so that it can easily be reloaded during debugging. The data format should be designed by you.
13 |
14 | 2. Write queries to retrieve and print all the data you entered. Try to print the data so that it is easy to understand (for example, print appropriate headings, such as: Customers, Compact Cars, SUVs, Current Rentals, etc.).
15 |
16 | 3. Write a query that will prepare a report for weekly earnings by owner, by car type and per car unit that owner owns within that car type.
17 |
18 | 4. Write the following database update transactions using either PRO*C or JAVA/JDBC or PHP or some other programming language or scripting language.
19 |
20 | 4.1 The first transaction is to add information about a new CUSTOMER.
21 |
22 | 4.2 The second transaction is to add all the information about a new CAR.
23 |
24 | 4.3 The third transaction is to add all the information about a new RENTAL reservation (this must find a free car of the appropriate type for the rental period).
25 |
26 | 4.4 The fourth transaction is to handle the return of a rented car. This transaction should print the total customer payment due for the rental, and enter it in the database.
27 |
28 | 4.5 The fifth transaction is to enter or update the rental rates (daily and weekly) for a type of car.
29 |
30 | 5. Each transaction should have a user friendly interface to enter the information needed by the transaction. This can either be a Web-based interface, a command line interface, or a forms interface.
31 |
32 | 6. Test your transactions by adding a few new customers, cars, reservations, by changing some rental rates and reservations rates.
33 |
34 |
35 | **Assumptions for EER Diagram:**
36 | - One customer can rent one car at a time so the cardinality ratio will be 1:1.
37 | - A car is divided into different types of disjoint entities with attribute type.
38 | - A single owner may own multiple cars.
39 | - Each customer pays for their respective rentals .
40 | - The customer might pay an advance or security deposit which is used in calculating final amount.
41 | - Discount is given for membership customers
42 | - Driver charge also added if customer opted for chauffeur.
43 | - Each rental will be divided into two distinct entities Daily and weekly.
44 | - Amount can be derived using the CAR attributes Drate and Wrate.
45 | - Return date is also a derived attribute, which can be derived from Start Date and No of Days/weeks.
46 | - A single owner can own multiple vehicles so we consider this is a 1:n relation towards the car entity from the owner entity.
47 | - A customer can provide feedback which can be referred by the Customer service Department for better service in future.
48 | - A customer has a choice to either hire a chauffeur or choose self-drive option.
49 |
50 |
51 | **RELATIONAL SCHEMA MAPPING** :
52 | - Relationship between CAR and OWNER is 1:N , so we have created a new Relation OWNS which consists of foreign key attributes to CAR and OWNER relations.
53 | - RENTAL entity has two disjoint subclasses – DAILY and WEEKLY . While mapping we have created two relations DAILY and WEEKLY which have foreign key attributes to RENTAL relation.
54 | - DRIVER class has two super classes CHAUFFEUR and SELF. Customer can select any mode of driving. It has foreign key attribute to DRIVER crelation.
55 | - CAR entity has six disjoint subclasses (Specialization) which has been done on Type attribute. Single Relation Mapping technique has been used here.
56 | - All 1:1 relationships has been mapped using foreign key technique.
57 | Note: The Schema Diagram is present in the folder as Schema_Diagram.pdf
58 |
59 |
60 |
--------------------------------------------------------------------------------
/Schema_Diagram.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dhanukarajat/car-rental/33eefab4e1626140cc19433e8872a2964ef68ee2/Schema_Diagram.pdf
--------------------------------------------------------------------------------