Answer
Answer
OPEN cur;
read_loop: LOOP
FETCH cur INTO booking_id, user_id, showtime_id;
IF done THEN
LEAVE read_loop;
END IF;
END LOOP;
CLOSE cur;
END //
DELIMITER ;
DELIMITER ;
DELIMITER ;
Handling Concurrent Reservations:
For concurrency, we can lock the book record for
updates to prevent multiple reservations at the same
time:
START TRANSACTION;
COMMIT;
DELIMITER ;
COMMIT;
OPEN reorder_cursor;
read_loop: LOOP
FETCH reorder_cursor INTO prod_id, qty;
IF done THEN
LEAVE read_loop;
END IF;
CLOSE reorder_cursor;
END;
5. Performance:
o Use indexes on frequently queried fields (e.g.,
product_name, supplier_id) to speed up
queries, particularly for finding the fastest
delivery routes.
COMMIT;
5. Optimization: Use Indexing for Routes and
Vehicle Utilization:
o Index vehicle_id in the Assignments table
and route_id in the Routes table for faster
querying.
CREATE INDEX idx_vehicle_id ON Assignments
(vehicle_id);
CREATE INDEX idx_route_id ON Routes (route_id);
COMMIT;
COMMIT;
5. Optimization: Real-Time Ticket Availability
and Price Estimates:
o Indexing for faster queries related to
schedule availability and ticket price
calculations.
CREATE INDEX idx_schedule_id ON Schedules
(schedule_id);
CREATE INDEX idx_route_id ON Routes (route_id);
COMMIT;
28. Database Design for a Customer Relationship
Management (CRM) System
Objective:
Build a CRM system database to track customer
interactions, sales pipelines, and marketing campaigns.
Exercise:
Scenario:
Design a CRM system to manage customer interactions,
sales opportunities, and marketing efforts.
Tasks:
1. Design Tables:
o Customer Table: Stores customer details.
o Sales Opportunities Table: Tracks potential
sales for each customer.
o Activities Table: Logs interactions with
customers.
o Leads Table: Stores details of sales leads.
o Campaigns Table: Tracks marketing
campaigns.
CREATE TABLE Customers (
customer_id INT PRIMARY KEY,
customer_name VARCHAR(255),
customer_email VARCHAR(255),
customer_phone VARCHAR(15)
);
CREATE TABLE Sales_Opportunities (
opportunity_id INT PRIMARY KEY,
customer_id INT,
opportunity_description VARCHAR(255),
value DECIMAL(15, 2),
status VARCHAR(50),
FOREIGN KEY (customer_id) REFERENCES
Customers(customer_id)
);