-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.sql
More file actions
48 lines (43 loc) · 1.43 KB
/
Copy pathdatabase.sql
File metadata and controls
48 lines (43 loc) · 1.43 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
-- Car Rental Agency DB
-- run this to set up the database
CREATE DATABASE IF NOT EXISTS car_rental;
USE car_rental;
CREATE TABLE customers (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
email VARCHAR(100) NOT NULL UNIQUE,
phone VARCHAR(15),
password VARCHAR(255) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE agencies (
id INT AUTO_INCREMENT PRIMARY KEY,
agency_name VARCHAR(150) NOT NULL,
email VARCHAR(100) NOT NULL UNIQUE,
phone VARCHAR(15),
address TEXT,
password VARCHAR(255) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE cars (
id INT AUTO_INCREMENT PRIMARY KEY,
agency_id INT NOT NULL,
vehicle_model VARCHAR(100) NOT NULL,
vehicle_number VARCHAR(30) NOT NULL UNIQUE,
seating_capacity INT NOT NULL,
rent_per_day DECIMAL(10,2) NOT NULL,
is_available TINYINT(1) DEFAULT 1,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (agency_id) REFERENCES agencies(id) ON DELETE CASCADE
);
CREATE TABLE bookings (
id INT AUTO_INCREMENT PRIMARY KEY,
car_id INT NOT NULL,
customer_id INT NOT NULL,
start_date DATE NOT NULL,
num_days INT NOT NULL,
total_cost DECIMAL(10,2) NOT NULL,
booked_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (car_id) REFERENCES cars(id) ON DELETE CASCADE,
FOREIGN KEY (customer_id) REFERENCES customers(id) ON DELETE CASCADE
);