Question: This is my SQL code, and I can not run it. Please give a fix and correct run screenshots!!!!! Here is my all codes: CREATE
This is my SQL code, and I can not run it. Please give a fix and correct run screenshots!!!!!
Here is my all codes:
CREATE TABLE clients ( client_id INT PRIMARY KEY, client_name VARCHAR(50), client_age INT, registration_date DATE );
CREATE TABLE vehicles ( vehicle_id INT PRIMARY KEY, vehicle_type VARCHAR(50), vehicle_model VARCHAR(50), rental_price DECIMAL(8,2) );
CREATE TABLE reservations ( reservation_id INT PRIMARY KEY, client_id INT, vehicle_id INT, start_date DATE, end_date DATE, estimate_budget DECIMAL(8,2), payment DECIMAL(8,2), CONSTRAINT fk_client_id FOREIGN KEY (client_id) REFERENCES clients(client_id), CONSTRAINT fk_vehicle_id FOREIGN KEY (vehicle_id) REFERENCES vehicles(vehicle_id) );
CREATE TABLE black_list ( client_id INT PRIMARY KEY, reason VARCHAR(100) );
CREATE TABLE stats ( year INT PRIMARY KEY, total_revenue DECIMAL(10,2), total_reservations INT ); INSERT INTO clients (client_id, client_name, client_age, registration_date) VALUES (1, 'John Smith', 30, '2022-01-01'), (2, 'Jane Doe', 25, '2022-02-01'), (3, 'Bob Johnson', 19, '2022-03-01');
INSERT INTO vehicles (vehicle_id, vehicle_type, vehicle_model, rental_price) VALUES (1, 'SUV', 'Toyota RAV4', 60), (2, 'SEDAN', 'Honda Civic', 40), (3, 'TRUCK', 'Ford F-150', 80);
-- Reservation with estimated budget and start date INSERT INTO reservations (client_id, vehicle_id, start_date, end_date, estimate_budget, payment) VALUES (1, 1, '2022-03-01', '2022-03-05', 300, NULL);
-- Blacklist entry INSERT INTO black_list (client_id, reason) VALUES (3, 'Car returned with damage');
-- Stats entry INSERT INTO stats (year, total_revenue, total_reservations) VALUES (2022, 500, 5); -- Procedure for making a reservation and returning the reservation ID CREATE PROCEDURE make_reservation (IN client_id INT, IN vehicle_id INT, IN start_date DATE, IN end_date DATE, IN estimate_budget DECIMAL(8,2), OUT reservation_id INT) BEGIN -- Check if client is 18 or over SELECT client_age INTO @age FROM clients WHERE client_id = client_id; IF (@age rent_end_date THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Cannot return car after end date'; END IF; SELECT EXISTS(SELECT 1 FROM blacklist WHERE client_id = client_id) INTO is_blacklisted; IF is_blacklisted THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Client is blacklisted'; END IF; SELECT EXISTS(SELECT 1 FROM vehicle_issue WHERE reservation_id = reservation_id) INTO is_vehicle_issue; IF is_vehicle_issue THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Vehicle is not in good condition'; END IF; SELECT DATEDIFF(rent_end_date, rent_start_date) INTO rent_days; IF rent_days > 10 THEN SET discount = estimate_budget * 0.1; END IF; SET christmas = CONCAT(YEAR(CURDATE()), '-12-25'); IF (rent_start_date
DELETE FROM reservation WHERE end_date IS NULL AND YEAR(start_date) = YEAR(NOW());
INSERT INTO archived_reservation SELECT * FROM reservation WHERE end_date IS NOT NULL;
INSERT INTO stats (year, total_reservations, total_revenue) SELECT YEAR(end_date), COUNT(*), SUM(total_cost) FROM archived_reservation GROUP BY YEAR(end_date);
please give all correct run screenshots !!! SQL
INSERT INTO reservations (client_id, vehicle_id, start_date, end_date, estimate_budget, payme VALUES (1, 1, '2022-03-01', '2022-03-05', 300, NULL)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
