BCA 3RD SEMESTER

DBMS SQL Assignment

Database Management System – Practical Questions & Answers

📘 Database Information

Database: college_DB
The database has already been created. First execute the setup query below to select the database and create the required tables.

DB

Database Table Setup

Select the existing college_DB database and create all three tables.

MYSQL TABLE CREATION
USE college_DB;

CREATE TABLE IF NOT EXISTS student (
    student_id INT PRIMARY KEY,
    student_name VARCHAR(100) NOT NULL,
    gender VARCHAR(10),
    department VARCHAR(50),
    semester INT
);

CREATE TABLE IF NOT EXISTS course (
    course_id INT PRIMARY KEY,
    course_name VARCHAR(100) NOT NULL,
    credits INT
);

CREATE TABLE IF NOT EXISTS enrollment (
    student_id INT,
    course_id INT,
    marks INT,
    PRIMARY KEY (student_id, course_id),
    FOREIGN KEY (student_id) REFERENCES student(student_id),
    FOREIGN KEY (course_id) REFERENCES course(course_id)
);
✓ Expected Result All three tables are created successfully inside college_DB.
01

Question 1

Insert at least five records in each table.

1. STUDENT Table

INSERT QUERY
INSERT INTO student
(student_id, student_name, gender, department, semester)
VALUES
(101, 'Rahul', 'Male', 'BCA', 3),
(102, 'Priya', 'Female', 'BCA', 3),
(103, 'Amit', 'Male', 'BCA', 3),
(104, 'Sneha', 'Female', 'BBA', 3),
(105, 'Rohan', 'Male', 'BCA', 3);

2. COURSE Table

INSERT QUERY
INSERT INTO course
(course_id, course_name, credits)
VALUES
(201, 'DBMS', 4),
(202, 'Java', 4),
(203, 'Python', 3),
(204, 'Data Structure', 4),
(205, 'Computer Networks', 3);

3. ENROLLMENT Table

INSERT QUERY
INSERT INTO enrollment
(student_id, course_id, marks)
VALUES
(101, 201, 85),
(102, 201, 90),
(103, 202, 78),
(104, 204, 88),
(105, 204, 95);
✓ Result Five records are inserted into each table.
02

Question 2

Display the total number of students.

SQL QUERY
SELECT COUNT(*) AS Total_Students
FROM student;
✓ Expected Output
Total_Students
5
03

Question 3

Display students in descending order of marks.

SQL QUERY
SELECT
    student.student_id,
    student.student_name,
    enrollment.marks
FROM student
JOIN enrollment
ON student.student_id = enrollment.student_id
ORDER BY enrollment.marks DESC;
✓ Expected Output
Student ID Name Marks
105Rohan95
102Priya90
104Sneha88
101Rahul85
103Amit78
04

Question 4

Display all courses where students have no enrollment.

SQL QUERY
SELECT
    course.course_id,
    course.course_name
FROM course
LEFT JOIN enrollment
ON course.course_id = enrollment.course_id
WHERE enrollment.course_id IS NULL;
✓ Expected Output
Course ID Course Name
203 Python
205 Computer Networks
05

Question 5

Find students who got the maximum marks.

SQL QUERY
SELECT
    student.student_id,
    student.student_name,
    enrollment.marks
FROM student
JOIN enrollment
ON student.student_id = enrollment.student_id
WHERE enrollment.marks = (
    SELECT MAX(marks)
    FROM enrollment
);
✓ Expected Output
Student ID Name Marks
105 Rohan 95
06

Question 6

Find students enrolled in a particular course.

SQL QUERY
SELECT
    student.student_id,
    student.student_name,
    course.course_name
FROM student
JOIN enrollment
ON student.student_id = enrollment.student_id
JOIN course
ON enrollment.course_id = course.course_id
WHERE course.course_name = 'DBMS';
✓ Expected Output Students enrolled in DBMS:
Student ID Name Course
101RahulDBMS
102PriyaDBMS
07

Question 7

Display the number of students in each department.

SQL QUERY
SELECT
    department,
    COUNT(*) AS Total_Students
FROM student
GROUP BY department;
✓ Expected Output
Department Total Students
BCA4
BBA1
08

Question 8

Display minimum marks of students.

SQL QUERY
SELECT MIN(marks) AS Minimum_Marks
FROM enrollment;
✓ Expected Output
Minimum_Marks
78
09

Question 9

Display maximum marks obtained in each department.

SQL QUERY
SELECT
    student.department,
    MAX(enrollment.marks) AS Maximum_Marks
FROM student
JOIN enrollment
ON student.student_id = enrollment.student_id
GROUP BY student.department;
✓ Expected Output
Department Maximum Marks
BCA95
BBA88
10

Question 10

Find students who have obtained the lowest marks in a particular course.

SQL QUERY
SELECT
    student.student_id,
    student.student_name,
    enrollment.marks,
    course.course_name
FROM student
JOIN enrollment
ON student.student_id = enrollment.student_id
JOIN course
ON enrollment.course_id = course.course_id
WHERE course.course_name = 'DBMS'
AND enrollment.marks = (
    SELECT MIN(e.marks)
    FROM enrollment e
    JOIN course c
    ON e.course_id = c.course_id
    WHERE c.course_name = 'DBMS'
);
✓ Expected Output
Student ID Name Marks Course
101 Rahul 85 DBMS