DBMS SEM LAB SET 2
DBMS SEM LAB SET 2
Create a student database table, add constraints (primary key, check), insert rows, update
and delete rows using DDL and DML commands.
2. a) Create a set of tables for Bus reservation database, add foreign key constraints and
incorporate referential integrity.
b)Create PL SQL triggers for bus reservation system cancellation and reservation actions.
-- Add a bus
INSERT INTO Buses (bus_number, capacity, bus_type) VALUES ('BUS101', 40, 'AC');
-- Add a route
INSERT INTO Routes (source, destination, travel_time) VALUES ('CityA', 'CityB', '4
hours');
-- Add a passenger
INSERT INTO Passengers (name, phone, email) VALUES ('Love', '1234567890',
'[email protected]');
INSERT INTO Reservations (passenger_id, bus_id, route_id, seat_number, reservation_date)
VALUES (1, 1, 1, 5, CURDATE());
3. a) Create a Product, Sales and purchase table using DDL and DML commands.
-- Employees
INSERT INTO employee_personal VALUES (101, 'Shreya', 1);
INSERT INTO employee_personal VALUES (102, 'Ravi', 2);
INSERT INTO employee_personal VALUES (103, 'Anita', 3);
-- Salaries
INSERT INTO Salary VALUES (101, 50000);
INSERT INTO Salary VALUES (102, 45000);
INSERT INTO Salary VALUES (103, 60000);
b) Create a user-defined function to update an employee's salary when they receive incentives.
5.
a) Create an online shopping database using DDL and DML commands. Use subqueries to
present the information about the items you've purchased.
-- Customers
INSERT INTO Customers VALUES (1, 'Shreya');
INSERT INTO Customers VALUES (2, 'Ravi');
-- Products
INSERT INTO Products VALUES (1, 'Laptop', 70000);
INSERT INTO Products VALUES (2, 'Headphones', 3000);
INSERT INTO Products VALUES (3, 'Smartphone', 25000);
-- Orders
INSERT INTO Orders VALUES (101, 1, '2025-06-01');
INSERT INTO Orders VALUES (102, 2, '2025-06-02');
-- Order_Items
INSERT INTO Order_Items VALUES (1001, 101, 1, 1); -- Shreya bought 1 Laptop
INSERT INTO Order_Items VALUES (1002, 101, 2, 2); -- Shreya bought 2 Headphones
INSERT INTO Order_Items VALUES (1003, 102, 3, 1); -- Ravi bought 1 Smartphone
b) Write PL SQL Triggers to display available items after a successful purchase andalso
display the available items before purchasing.
6. Create wedding hall reservation database using DDL and DML commands and also
displaythe results after applying join operation.
-- Halls
INSERT INTO Halls VALUES (1, 'Grand Palace', 300, 'Downtown');
INSERT INTO Halls VALUES (2, 'Royal Garden', 150, 'Uptown');
INSERT INTO Halls VALUES (3, 'Sunshine Hall', 200, 'Midtown');
-- Customers
INSERT INTO Customers VALUES (101, 'Shreya', '9876543210');
INSERT INTO Customers VALUES (102, 'Ravi', '9123456780');
-- Reservations
INSERT INTO Reservations VALUES (1001, 101, 1, '2025-12-20', 5);
INSERT INTO Reservations VALUES (1002, 102, 3, '2025-11-15', 3);
7.
a) Create a database for a car manufacturing company and use the having clause to display
thecar models based on price.
Left Join
Right Join