DBMS Lab QuestionsDBMS Lab Questions
Questions 1: Student-Course Database
CREATE TABLE Students (
student_id INT PRIMARY KEY,
name VARCHAR(50) NOT NULL,
email VARCHAR(100) UNIQUE,
dept VARCHAR(50)
);
CREATE TABLE Courses (
course_id INT PRIMARY KEY,
course_name VARCHAR(50),
credits INT
);
CREATE TABLE Enrollments (
student_id INT,
course_id INT,
FOREIGN KEY (student_id) REFERENCES Students(student_id),
FOREIGN KEY (course_id) REFERENCES Courses(course_id)
);
- Display all students enrolled in a specific course.
- Find students not enrolled in any course.
- Create a view of student-course details.
- Find students enrolled in more than one course using nested query.
- Use UNION to combine student names from two departments.
Questions 2: Employee-Department Database
CREATE TABLE Departments (
dept_id INT PRIMARY KEY,
dept_name VARCHAR(50)
);
CREATE TABLE Employees (
emp_id INT PRIMARY KEY,
name VARCHAR(50),
salary INT,
dept_id INT,
FOREIGN KEY (dept_id) REFERENCES Departments(dept_id)
);
- List employees with their department names.
- Find highest paid employee using nested query.
- Show employees without department.
- Create a view for employees with salary greater than 50000.
- Use INTERSECT for salary comparison.
Questions 3: Library Management
CREATE TABLE Books (
book_id INT PRIMARY KEY,
title VARCHAR(100),
author VARCHAR(50)
);
CREATE TABLE Members (
member_id INT PRIMARY KEY,
name VARCHAR(50)
);
CREATE TABLE Issued (
book_id INT,
member_id INT,
FOREIGN KEY (book_id) REFERENCES Books(book_id),
FOREIGN KEY (member_id) REFERENCES Members(member_id)
);
- List books issued to members.
- Find books not issued.
- Create a view of issued books.
- Find members who issued more than 2 books.
- Use EXCEPT to find books not issued.
Questions 4: Online Shopping
CREATE TABLE Customers (
cust_id INT PRIMARY KEY,
name VARCHAR(50)
);
CREATE TABLE Orders (
order_id INT PRIMARY KEY,
cust_id INT,
FOREIGN KEY (cust_id) REFERENCES Customers(cust_id)
);
CREATE TABLE Products (
product_id INT PRIMARY KEY,
product_name VARCHAR(50)
);
- List customers and their orders.
- Find customers without orders.
- Create a view of customer orders.
- Find customers who placed more than one order.
- Use UNION of customer and product names.
Questions 5: Hospital Database
CREATE TABLE Doctors (
doc_id INT PRIMARY KEY,
name VARCHAR(50)
);
CREATE TABLE Patients (
patient_id INT PRIMARY KEY,
name VARCHAR(50)
);
CREATE TABLE Appointments (
doc_id INT,
patient_id INT,
FOREIGN KEY (doc_id) REFERENCES Doctors(doc_id),
FOREIGN KEY (patient_id) REFERENCES Patients(patient_id)
);
- List doctor-patient appointments.
- Find doctors with no patients.
- Create a view of appointments.
- Find doctors treating more than 2 patients.
- Use INTERSECT for patients.
Questions 6: Banking System
CREATE TABLE Customers (
cust_id INT PRIMARY KEY,
name VARCHAR(50)
);
CREATE TABLE Accounts (
acc_id INT PRIMARY KEY,
cust_id INT,
balance INT,
FOREIGN KEY (cust_id) REFERENCES Customers(cust_id)
);
- List customers with account details.
- Find customers with no accounts.
- Create view for high balance accounts.
- Find customer with maximum balance.
- Use EXCEPT for customers without accounts.
Questions 7: College Faculty
CREATE TABLE Faculty (
faculty_id INT PRIMARY KEY,
name VARCHAR(50)
);
CREATE TABLE Subjects (
subject_id INT PRIMARY KEY,
subject_name VARCHAR(50)
);
CREATE TABLE Teaching (
faculty_id INT,
subject_id INT,
FOREIGN KEY (faculty_id) REFERENCES Faculty(faculty_id),
FOREIGN KEY (subject_id) REFERENCES Subjects(subject_id)
);
- List faculty with subjects.
- Find faculty not teaching any subject.
- Create teaching view.
- Find faculty teaching more than 2 subjects.
- Use UNION of faculty and subject names.
Questions 8: Hotel Booking
CREATE TABLE Guests (
guest_id INT PRIMARY KEY,
name VARCHAR(50)
);
CREATE TABLE Rooms (
room_id INT PRIMARY KEY,
type VARCHAR(50)
);
CREATE TABLE Booking (
guest_id INT,
room_id INT,
FOREIGN KEY (guest_id) REFERENCES Guests(guest_id),
FOREIGN KEY (room_id) REFERENCES Rooms(room_id)
);
- List guests with booked rooms.
- Find unbooked rooms.
- Create booking view.
- Find guests with multiple bookings.
- Use EXCEPT for rooms not booked.
Questions 9: Movie Database
CREATE TABLE Movies (
movie_id INT PRIMARY KEY,
title VARCHAR(50)
);
CREATE TABLE Actors (
actor_id INT PRIMARY KEY,
name VARCHAR(50)
);
CREATE TABLE Casts (
movie_id INT,
actor_id INT,
FOREIGN KEY (movie_id) REFERENCES Movies(movie_id),
FOREIGN KEY (actor_id) REFERENCES Actors(actor_id)
);
- List movies with actors.
- Find movies without actors.
- Create movie-cast view.
- Find actors in multiple movies.
- Use INTERSECT for actors.
Questions 10: Transport System
CREATE TABLE Drivers (
driver_id INT PRIMARY KEY,
name VARCHAR(50)
);
CREATE TABLE Vehicles (
vehicle_id INT PRIMARY KEY,
type VARCHAR(50)
);
CREATE TABLE Assignments (
driver_id INT,
vehicle_id INT,
FOREIGN KEY (driver_id) REFERENCES Drivers(driver_id),
FOREIGN KEY (vehicle_id) REFERENCES Vehicles(vehicle_id)
);
- List drivers with vehicles.
- Find drivers without vehicles.
- Create assignment view.
- Find drivers assigned multiple vehicles.
- Use UNION for drivers and vehicle types.