DBMS Practice Questions
DBMS Practice Questions
Scenario-Based Questions
1. 1. A university wants to list the names of students enrolled in the course 'Database
Systems' along with their grades.
Answer:
2. 2. The administration wants to find students who are enrolled in more than one course.
Answer:
SELECT StudentID
FROM Enrollments
GROUP BY StudentID
HAVING COUNT(CourseID) > 1;
3. 3. Generate a report of students with an 'A' grade in any course, showing their name,
course name, and department.
Answer:
4. 4. A student wants a complete list of their enrolled courses with credit hours and
grades. Write a query for StudentID = 1.
Answer:
5. 5. The university wants to find out which students in 'Computer Science' have scored
grade 'A'.
Answer:
SELECT s.Name
FROM Students s
JOIN Enrollments e ON s.StudentID = e.StudentID
WHERE s.Department = 'Computer Science' AND e.Grade = 'A';
Table-Based Questions
6. 1. Create a table named Students with columns: StudentID (Primary Key), Name, Age,
Department.
Answer:
Answer:
Answer:
Answer:
Answer:
Answer:
SELECT s.Name
FROM Students s
JOIN Enrollments e ON s.StudentID = e.StudentID
JOIN Courses c ON e.CourseID = c.CourseID
WHERE c.CourseName = 'Database Systems';
12. 2. Scenario: Show student names and course names they are enrolled in.
Answer:
13. 3. Scenario: List the names of students who received grade 'A'.
Answer:
SELECT s.Name
FROM Students s
JOIN Enrollments e ON s.StudentID = e.StudentID
WHERE e.Grade = 'A';
14. 4. Scenario: Get courses that student 'Sara' is enrolled in.
Answer:
SELECT c.CourseName
FROM Students s
JOIN Enrollments e ON s.StudentID = e.StudentID
JOIN Courses c ON e.CourseID = c.CourseID
WHERE s.Name = 'Sara';
15. 5. Scenario: Find students in the 'Computer Science' department enrolled in any course.
Answer:
16. 6. Scenario: List all courses that have at least one student enrolled.
Answer:
17. 7. Scenario: Get students and their grades for the course 'Data Structures'.
Answer:
18. 8. Scenario: List students with their departments and enrolled course names.
Answer:
Answer:
SELECT Name
FROM Students
WHERE StudentID NOT IN (SELECT StudentID FROM Enrollments);
Answer:
SELECT CourseName
FROM Courses
WHERE CourseID NOT IN (SELECT CourseID FROM Enrollments);
21. 11. Scenario: Find students with grades other than 'A'.
Answer:
22. 12. Scenario: Get course names with more than one student enrolled.
Answer:
SELECT c.CourseName
FROM Courses c
JOIN Enrollments e ON c.CourseID = e.CourseID
GROUP BY c.CourseName
HAVING COUNT(e.StudentID) > 1;
23. 13. Scenario: Show the total number of courses each student is enrolled in.
Answer:
Answer:
25. 15. Scenario: List all student-course-grade details sorted by student name.
Answer:
26. 16. Scenario: Find the average age of students enrolled in 'Database Systems'.
Answer:
SELECT AVG(s.Age)
FROM Students s
JOIN Enrollments e ON s.StudentID = e.StudentID
JOIN Courses c ON c.CourseID = e.CourseID
WHERE c.CourseName = 'Database Systems';
27. 17. Scenario: Show the grade distribution for the course 'Data Structures'.
Answer:
Answer:
29. 19. Scenario: List courses and number of students enrolled in each.
Answer:
30. 20. Scenario: Find names of students who have taken both 'Database Systems' and 'Data
Structures'.
Answer:
SELECT s.Name
FROM Students s
JOIN Enrollments e1 ON s.StudentID = e1.StudentID
JOIN Courses c1 ON e1.CourseID = c1.CourseID
JOIN Enrollments e2 ON s.StudentID = e2.StudentID
JOIN Courses c2 ON e2.CourseID = c2.CourseID
WHERE c1.CourseName = 'Database Systems'
AND c2.CourseName = 'Data Structures';