wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Quiz on collegeDB

Total questions: 31

Worksheet time: 18mins

Name
Class
Date
1.

CREATE DATABASE CollegeDB;

USE CollegeDB;

CREATE TABLE Department (

DeptID INT PRIMARY KEY AUTO_INCREMENT,

DeptName VARCHAR(50) NOT NULL UNIQUE,

Location VARCHAR(50)

);

CREATE TABLE Student (

StudentID INT PRIMARY KEY AUTO_INCREMENT,

Name VARCHAR(50) NOT NULL,

Gender CHAR(1) CHECK (Gender IN ('M', 'F')),

DOB DATE NOT NULL,

DeptID INT,

Email VARCHAR(100) UNIQUE,

Phone VARCHAR(15) DEFAULT 'N/A',

FOREIGN KEY (DeptID) REFERENCES Department(DeptID)

ON DELETE SET NULL

ON UPDATE CASCADE

);

CREATE TABLE Course (

CourseID INT PRIMARY KEY AUTO_INCREMENT,

CourseName VARCHAR(100) NOT NULL,

Credits INT CHECK (Credits BETWEEN 1 AND 6),

DeptID INT NOT NULL,

FOREIGN KEY (DeptID) REFERENCES Department(DeptID)

ON DELETE CASCADE

);

CREATE TABLE Enrollment (

EnrollmentID INT PRIMARY KEY AUTO_INCREMENT,

StudentID INT NOT NULL,

CourseID INT NOT NULL,

EnrollDate DATE DEFAULT (CURRENT_DATE),

Grade CHAR(2) CHECK (Grade IN ('A', 'B', 'C', 'D', 'F', 'NA')),

FOREIGN KEY (StudentID) REFERENCES Student(StudentID)

ON DELETE CASCADE,

FOREIGN KEY (CourseID) REFERENCES Course(CourseID)

ON DELETE CASCADE,

UNIQUE (StudentID, CourseID)

);

1.

Based on the above passage, which column is the primary key in the Department table?

a)

DeptName

b)

DeptID

c)

Location

d)

CourseID

2.

Which column is the primary key in the Department table?

a)

DeptName

b)

DeptID

c)

Location

d)

CourseID

3.

The Student table has a Gender column with a CHECK constraint. Which values are valid?

a)

'M' and 'F'

b)

'Male' and 'Female'

c)

Any single letter

d)

Only 'F'

4.

What happens if a Department is deleted that still has students linked to it?

a)

Error occurs

b)

Student records are deleted

c)

Student DeptID becomes NULL

d)

No effect

5.

Which constraint ensures no two students enroll in the same course twice?

a)

PRIMARY KEY

b)

UNIQUE

c)

CHECK

d)

DEFAULT

6.

Which table has both StudentID and CourseID as foreign keys?

a)

Course

b)

Department

c)

Enrollment

d)

Student

7.

The default value of Phone in the Student table is:

a)

NULL

b)

'Unknown'

c)

'N/A'

d)

Empty string

8.

The Course table has a CHECK constraint on credits. Which entry is invalid?

a)

3

b)

5

c)

6

d)

8

9.

If the Department name must not be repeated, which constraint is used?

a)

NOT NULL

b)

UNIQUE

c)

DEFAULT

d)

FOREIGN KEY

10.

Which constraint ensures that no NULL values are allowed in DeptName?

a)

UNIQUE

b)

NOT NULL

c)

CHECK

d)

FOREIGN KEY

11.

Which of the following is a referential integrity constraint?

a)

UNIQUE

b)

CHECK

c)

FOREIGN KEY

d)

DEFAULT

12.

To get all students from the “Computer Science” department:

a)

INNER JOIN

b)

LEFT JOIN

c)

CROSS JOIN

d)

RIGHT JOIN

13.

To find students who have not enrolled in any course, which join would be most suitable?

a)

INNER JOIN

b)

LEFT JOIN with WHERE EnrollmentID IS NULL

c)

CROSS JOIN

d)

RIGHT JOIN

14.

To count total courses offered by each department:

a)

HAVING

b)

WHERE

c)

GROUP BY

d)

ORDER BY

15.

To show students born after 2002:

a)

GROUP BY

b)

HAVING

c)

WHERE

d)

ORDER BY

16.

What is returned by:

a)

Number of students

b)

Number of courses

c)

Total enrollment records

d)

Total departments

17.

To change a student’s department, which command is used?

a)

ALTER TABLE

b)

UPDATE

c)

INSERT

d)

RENAME

18.

Which SQL keyword is used to prevent duplicate rows in query output?

a)

DISTINCT

b)

UNIQUE

c)

CHECK

d)

GROUP BY

19.

To delete a department permanently:

a)

DROP DATABASE

b)

DELETE FROM Department

c)

TRUNCATE Department

d)

ALTER TABLE Department

20.

What happens when we insert a student with duplicate email?

a)

Inserts successfully

b)

Fails due to UNIQUE constraint

c)

Replaces old record

d)

Sets email to NULL

21.

Which query lists all courses with 4 credits?

a)

SELECT * FROM Course WHERE Credits = 4;

b)

SELECT CourseName FROM Course HAVING Credits = 4;

c)

SELECT * FROM Course GROUP BY Credits = 4;

d)

SELECT Credits = 4 FROM Course;

22.

If you delete a course, what happens to enrollments linked to it?

a)

They remain

b)

They are also deleted

c)

Set to NULL

d)

Database error

23.

Which SQL statement adds a new column “Address” to the Student table?

a)

ADD COLUMN Address VARCHAR(100)

b)

ALTER TABLE Student ADD Address VARCHAR(100);

c)

UPDATE Student ADD Address VARCHAR(100);

d)

INSERT COLUMN Address VARCHAR(100);

24.

Which of the following is NOT a DML command?

a)

SELECT

b)

INSERT

c)

DELETE

d)

CREATE

25.

Which command removes all data from Course but keeps the structure?

a)

DROP TABLE

b)

DELETE FROM Course

c)

TRUNCATE TABLE Course

d)

REMOVE TABLE Course

26.

To change the default phone value from 'N/A' to 'Unknown':

a)

ALTER TABLE Student MODIFY Phone DEFAULT 'Unknown';

b)

UPDATE Student SET DEFAULT 'Unknown';

c)

CHANGE DEFAULT Phone TO 'Unknown';

d)

INSERT DEFAULT 'Unknown';

27.

Which query lists the number of students per department?

a)

SELECT DeptID, COUNT(*) FROM Student GROUP BY DeptID;

b)

SELECT DeptID, COUNT(*) FROM Student;

c)

SELECT DeptID FROM Student;

d)

SELECT COUNT(*) FROM Student;

28.

Which of these ensures data consistency between tables?

a)

DEFAULT

b)

FOREIGN KEY

c)

CHECK

d)

UNIQUE

29.

Which of these will violate referential integrity?

a)

Deleting a department having students (ON DELETE SET NULL)

b)

Inserting student with non-existing DeptID

c)

Updating department name

d)

Viewing data

30.

To display department names and number of courses per department:

a)

SELECT D.DeptName, COUNT(C.CourseID) FROM Department D JOIN Course C ON D.DeptID = C.DeptID GROUP BY D.DeptName;

b)

SELECT D.DeptName FROM Department;

c)

SELECT COUNT(C.CourseID) FROM Course;

d)

SELECT D.DeptName, C.CourseID FROM Department D JOIN Course C;

31.

Which of the following ensures automatic date entry in Enrollment table?

a)

DEFAULT constraint

b)

CHECK constraint

c)

UNIQUE constraint

d)

PRIMARY KEY