You are on page 1of 9

23CD201 Database Management Systems CIA 1 QB

PART A

1. Design a ER Diagram for the following:

Primary Table: Book


Attributes: BookID (Primary Key), Title, ISBN, Genre, PublisherID (Foreign Key)

Secondary Table: Author


Attributes: AuthorID (Primary Key), Name, Birthdate, Country

Relationship:
 One book can have multiple authors.
 One author can write multiple books.

2. Write a short note on Cartesian Product, explain along with example.


3. Explain Normalization and give an example for 1 NF.
4. Discuss on Candidate Key and Super Key along with example.
5. Differentiate between Delete and Truncate SQL commands.
6. Write a short note on where clause and having by clause.
7. Write a SQL query to find the average salary of an employee whose salary is more than 90000.
Table Name: Employee
Fields: EmpId, EmpName, Desig, Dept, Salary
8. Write a nested query for the following:
Consider a database containing two tables: "Students" and "Grades". The "Students" table contains information about
students including their student ID and name, while the "Grades" table contains information about their exam grades
including student ID, subject, and grade.
Write the query to retrieve the names of students who scored higher than the average grade in the subject "Mathematics".
9. Write a correlated query for the following:
Consider a database with two tables: "Employees" and "Salaries". The "Employees" table contains information about
employees including their employee ID and name, while the "Salaries" table contains information about their salaries
including employee ID and salary amount.
Write a query to find employees who earn more than the average salary of their department.
10. Consider that there are two tables: "Students" and "Courses". The "Students" table contains information about students
including their student ID and name, and the "Courses" table contains information about courses including course ID and
course name. Write a SQL query to retrieve the names of students along with the names of the courses they are enrolled
in.
11. Design a ER Diagram for the following:

Primary Table: Movie


Attributes: MovieID (Primary Key), Title, ReleaseDate, Genre, DirectorID (Foreign Key)

Secondary Table: Director


Attributes: DirectorID (Primary Key), Name, Birthdate, Country
Relationship:

 One movie can have multiple directors.


 One director can direct multiple movies.
12. Explain the concept of Cartesian Product in relational databases and provide an example.
13. Explain the concept of Normalization in database design and provide an example for the Second
Normal Form (2NF).
14. Discuss the concepts of Primary Key and Foreign Key in database design, and provide an example for
each.
15. Differentiate between the DELETE and DROP SQL commands.
16. Write a short note on group by clause and having clause.
17. Write a SQL query to find the average salary of an employee whose salary is less than 150000.
Table Name: Employee
Fields: EmpId, EmpName, Desig, Dept, Salary
18. The database contains two tables: "Teachers" and "Subjects". The "Teachers" table contains information
about teachers, including their teacher ID and name, while the "Subjects" table contains information
about the subjects they teach, including teacher ID, subject name, and average exam score.
Write a nested query to retrieve the names of teachers who teach subjects with an average exam score
higher than the overall average score across all subjects.
19. The database contains two tables: "Products" and "Orders". The "Products" table contains information
about products, including their product ID and price, while the "Orders" table contains information
about customer orders, including product ID, quantity, and order ID.
Write a correlated query to find products that have been ordered more times than the average quantity
of orders for all products.
20. The database contains two tables: "Customers" and "Books". The "Customers" table contains
information about customers, including their customer ID and name, while the "Books" table contains
information about books, including book ID and title.
Write a SQL query to retrieve the names of customers along with the titles of the books they have
purchased.

PART – B

1.Consider a university database with the following tables:


Students (student_id, student_name, major, advisor_id)
Professors (professor_id, professor_name, department)
Courses (course_id, course_name, department, professor_id)
Enrollments (enrollment_id, student_id, course_id, grade)
The university wants to find the names of students who are majoring in Computer Science and
are enrolled in courses taught by Professor Smith.
Design a relational algebra expression to retrieve this information.
2. The database contains four tables: "Employees", "Projects", "Departments", and
"Assignments". The "Employees" table contains information about employees, including their
employee ID, name, and department ID. The "Projects" table contains information about
projects, including project ID and name. The "Departments" table contains information about
departments, including department ID and name.
Design a relational algebra expression to retrieve the names of employees who are assigned
to projects in the "Software Development" department.

3. The bookstore sells books, e-books, and audiobooks. Each book has a title, author(s), ISBN,
genre, and price. Authors have a name and a biography. Customers can register on the
website to purchase books, and their information includes name, email, and shipping address.
The bookstore also keeps track of orders, which include the customer who placed the order,
the book(s) purchased, the quantity, and the total price.
Design a set of normalized tables for the online bookstore database, ensuring that the
database is normalized up to at least third normal form (3NF). Provide explanations for each
normalization step.
4. The database should store information about students, courses, instructors, departments,
and enrollments. The goal is to ensure that the database is normalized up to at least third
normal form (3NF) to minimize redundancy and dependency and improve data integrity.

5. The university requires a database to manage student enrollment, courses, professors, and
departments. Each student can be enrolled in multiple courses, and each course can have
multiple students enrolled. Professors can teach multiple courses, and each course is taught
by one professor. Departments can offer multiple courses, and each course belongs to one
department. Design the database schema using DDL statements.

6. A company wants to create a database to manage its inventory, orders, customers, and
suppliers. Each product in the inventory can have multiple suppliers, and each supplier can
supply multiple products. Customers can place orders for multiple products, and each order
can contain multiple products. Design the database schema using DDL statements.

7. The database contains tables for products, customers, orders, and order details. Each
product has a unique product ID, name, description, and price. Customers can register on the
website and place orders for products. Each order consists of one or more products, and each
product can be part of multiple orders.
Table Name: Customer
Fields: customer_id (Primary Key), customer_name, email, shipping_address
Table Name: Products
Fields: product_id (Primary Key), product_name, description, price
Table Name: Orders
Fields: order_id (Primary Key), customer_id (Foreign Key), order_date
Table Name: Order_Details
Fields: order_detail_id (Primary Key), order_id (Foreign Key), product_id (Foreign Key),
quantity
Design SQL queries to perform the following tasks:

1. Insert a new customer record into the database.


2. Update the price of a product with a specific product ID.
3. Retrieve the total number of orders placed by each customer.
4. Delete a product record with a specific product ID.
8.Consider a database schema for a hospital system consisting of three tables: Patients,
Doctors, and Appointments.

Patients table contains information about patients with columns: PatientID, PatientName,
Age, and Gender.

Doctors table contains information about doctors with columns: DoctorID, DoctorName,
Specialization, and Experience.

Appointments table contains information about appointments with columns:


AppointmentID, PatientID (foreign key referencing Patients), DoctorID (foreign key
referencing Doctors), AppointmentDate, and Status.

Design SQL queries to perform the following tasks:

1. Calculate the total number of appointments made.


2. Find the average experience of doctors by specialization.
3. Identify the doctor with the most appointments.
4. Calculate the total number of appointments scheduled for each day.

9. A database of a small online store contains tables for products and orders. Each product
has a unique product ID, name, and price. Each order consists of one or more products, and
each product can be part of multiple orders.
Table Name: Products
Fields: product_id (Primary Key), name, price, stock_quantity
Table Name: Orders
Fields: order_id (Primary Key), customer_id, order_date
Table Name: Order_Details
Fields: order_detail_id (Primary Key), order_id (Foreign Key), product_id (Foreign Key),
quantity
Design SQL queries to perform the following tasks:

1. Retrieve the names of all products that are currently out of stock.
2. Find the names of all products that have been ordered at least once.
3. List the names of products that have never been ordered.
4. Retrieve the names of products that have been ordered by customers with a specific
customer ID.

10. Consider a database schema with two tables: Students and Grades. The Students table has
the following columns: StudentID, Name, and Age.

The Grades table has the following columns: StudentID (foreign key referencing Students),
Subject, and Grade.

Design SQL queries to perform the following tasks:

1.retrieve the names of students who have scored higher than the average grade in the subject
'Mathematics'.
2. Retrieve the names of students who are older than the average age of all students.

3. Retrieve the subjects in which the highest grade was achieved.

4. Retrieve the subjects in which at least one student has scored higher than the average grade.

11. The database contains tables for products, orders, and order details. Each product has a
unique product ID, name, and price. Each order consists of one or more products, and each
product can be part of multiple orders.
Table Name: Products
Fields: product_id (Primary Key), name, price
Table Name: Orders
Fields: order_id (Primary Key), order_date
Table Name: Order_Details
Fields: order_detail_id (Primary Key), order_id (Foreign Key), product_id (Foreign Key),
quantity
Design SQL queries to perform the following tasks:

1. Calculate the total number of orders placed.


2. Find the total revenue generated from all orders.
3. Retrieve the average price of products.
4. List the maximum and minimum prices of products.

12. Consider an employee database with two tables: Employees and Departments.

The Employees table contains the following columns: EmployeeID, Name, DepartmentID,
and Salary.

The Departments table contains the following columns: DepartmentID and DepartmentName

Design SQL queries to perform the following tasks:

1. retrieve the names of employees who are earning more than the average salary of all
employees in their respective departments.
2. Retrieve the names of employees who are earning more than the highest salary in their
respective departments.
3. Retrieve the names of employees who are earning more than the average salary of
employees in the same department with a higher employee ID.
4. Retrieve the names of employees who have the same salary as the employee with the
highest salary in their department.
13. The database contains tables for students and courses. Each student has a unique student
ID, name, and major. Each course has a unique course ID, name, and department. Additionally,
there is a table for enrollments, which tracks the courses each student is enrolled in.
Table Name: Students
Fields: student_id (Primary Key), name, major

Table Name: Courses


Fields: course_id (Primary Key), name, department

Table Name: Enrollments


Fields: enrollment_id (Primary Key), student_id (Foreign Key), course_id (Foreign Key)

Design SQL queries to perform the following tasks:

1. Retrieve the names of all students majoring in Computer Science.


2. Find the names of all courses offered by the Computer Science department.
3. List the names of students who are enrolled in at least one course offered by the Computer
Science department.
4. Retrieve the names of all students who are not enrolled in any course.

14. Consider a database schema with three tables: Employees, Departments, and Salaries.

The Employees table contains the following columns: EmployeeID, Name, and
DepartmentID.

The Departments table contains the following columns: DepartmentID and


DepartmentName.

The Salaries table contains the following columns: EmployeeID (foreign key referencing
Employees), Salary, and Year.

Design SQL queries to perform the following tasks:

1. retrieve the names of employees who have the highest salary in each department for the
year 2023.
2. Retrieve the department names along with the total salary expenditure for each
department in the year 2023.
3. Retrieve the names of employees who have changed departments at least once.

Retrieve the names of employees who have earned a salary higher than the average salary of
all employees in the year 2023.

15. The database contains tables for customers and orders. Each customer has a unique
customer ID and a name. Each order has a unique order ID, a customer ID, and an order
date. Additionally, there is a table for order details, which tracks the products purchased in
each order.
Table Name: Customers
Fields: customer_id (Primary Key), name
Table Name: Orders
Fields: order_id (Primary Key), customer_id (Foreign Key), order_date
Table Name: Order_Details
Fields: order_detail_id (Primary Key), order_id (Foreign Key), product_id (Foreign Key),
quantity
Design SQL queries to perform the following tasks:

1. Retrieve the names of customers who have placed orders.


2. Find the total number of orders placed by each customer.
3. List the names of customers who have placed more than one order.
4. Retrieve the names of customers who have placed an order after a specific date.

16. The database contains tables for products, orders, and customers. Each product has a
unique product ID, name, and price. Each order has a unique order ID, a customer ID, and a
date. Each customer has a unique customer ID and a name. Additionally, there is a table for
order details, which tracks the products purchased in each order.
Table Name: Customers
Fields: customer_id (Primary Key), name

Table Name: Orders


Fields: order_id (Primary Key), customer_id (Foreign Key), order_date

Table Name: Products


Fields: product_id (Primary Key), name, price

Table Name: Order_Details


Fields: order_detail_id (Primary Key), order_id (Foreign Key), product_id (Foreign Key),
quantity

Design SQL queries to perform the following tasks:

1. List the names of all products ordered by a specific customer.


2. Retrieve the total number of orders for a specific product.
3. Calculate the total revenue generated from a specific product.
4. List the names of customers who have never placed an order.

17.Consider the following database schema:

Customers table: Contains information about customers, with columns CustomerID, Name,
and Email.

Orders table: Contains information about orders placed by customers, with columns
OrderID, CustomerID (foreign key referencing Customers), ProductID (foreign key
referencing Products), and Quantity.

Products table: Contains information about products, with columns ProductID and
ProductName.

Design SQL queries to perform the following tasks:

1. retrieve the names of customers who have placed orders for products that are priced
higher than the average price of all products.
2. Retrieve the names of customers who have placed orders for more than one product.
3. Retrieve the names of customers who have placed orders for products with a total
quantity greater than the average quantity of all products.
4. Retrieve the names of customers who have placed orders for all available products.

18.Consider a database schema for a library system consisting of three tables: Books, Authors,
and BookAuthors.

Books table contains information about books with columns: BookID, Title, ISBN, and
Availability.

Authors table contains information about authors with columns: AuthorID, AuthorName.
BookAuthors table is a junction table linking books to authors with columns: BookID (foreign
key referencing Books) and AuthorID (foreign key referencing Authors).

Design SQL queries to perform the following tasks:

1. Retrieve the titles of books along with the names of authors for books that are currently
available.
2. Retrieve the titles of books along with the names of authors for books with ISBN
starting with '978'.
3. Retrieve the titles of books along with the names of authors for books written by
authors whose names start with 'J'.
4. Retrieve the titles of books along with the names of authors for books published after
the year 2010.

19. The database contains tables for students, courses, and enrollments. Each student has a
unique student ID, name, and major. Each course has a unique course ID, name, and
department. Additionally, there is a table for enrollments, which tracks the students enrolled in
each course.
Table Name: Students
Fields: student_id (Primary Key), name, major
Table Name: Courses
Fields: course_id (Primary Key), name, department
Table Name: Enrollments
Fields: enrollment_id (Primary Key), student_id (Foreign Key), course_id (Foreign Key)
Design SQL queries to perform the following tasks:

1. List the names of all courses taken by a specific student.


2. Retrieve the total number of courses taken by each student.
3. Calculate the total number of students enrolled in each department.
4. Retrieve the names of students who are not enrolled in any course.

20. Consider a database schema for a supermarket system consisting of three tables: Products,
Orders, and Customers.
Products table contains information about products with columns: ProductID, ProductName,
Category, and Price.

Orders table contains information about orders with columns: OrderID, CustomerID (foreign
key referencing Customers), ProductID (foreign key referencing Products), Quantity, and
OrderDate.

Customers table contains information about customers with columns: CustomerID,


CustomerName, Address, and Phone.

Design SQL queries to perform the following tasks:

1. Retrieve the names of customers along with the total amount spent by each customer.
2. Retrieve the product names along with the total quantity sold for each product.
3. Retrieve the product names along with the total quantity sold for each product.
4. Retrieve the names of customers along with the products they have ordered, ordered
in descending order of order dates.

You might also like