wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

DAY 22 MySQL: Constraints, Normalization (9th JULY 24)

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

Which query adds a primary key constraint to the 'id' column

in the 'students' table?

a)

ALTER TABLE students ADD CONSTRAINT PRIMARY

KEY (id);

b)

ALTER TABLE students ADD PRIMARY KEY (id);

c)

UPDATE TABLE students SET PRIMARY KEY (id);

d)

MODIFY TABLE students SET PRIMARY KEY (id);

2.

Which query creates a table 'enrollments' with a foreign key

constraint referencing 'students' ?

a)

CREATE TABLE enrollments (student_id INT, course_id

INT, FOREIGN KEY (student_id) REFERENCES

students(id));

b)

CREATE TABLE enrollments (student_id INT, course_id

INT, SET FOREIGN KEY (student_id) TO students(id));

c)

CREATE TABLE enrollments (student_id INT, course_id

INT, ADD FOREIGN KEY (student_id) REFERENCES

students(id));

d)

CREATE TABLE enrollments (student_id INT, course_id

INT, ADD CONSTRAINT FOREIGN KEY (student_id)

REFERENCES students(id));

3.

Which query removes a unique constraint from the 'email'

column in the 'students' table?

a)

ALTER TABLE students DROP UNIQUE (email);

b)

ALTER TABLE students REMOVE UNIQUE (email);

c)

ALTER TABLE students DELETE UNIQUE (email);

d)

ALTER TABLE students DROP CONSTRAINT UNIQUE

(email);

4.

Which query sets a default value of 'Active' for the 'status'

column in the 'students' table?

a)

ALTER TABLE students SET DEFAULT 'Active' FOR

status;

b)

ALTER TABLE students CHANGE DEFAULT 'Active' FOR

status;

c)

ALTER TABLE students MODIFY status SET DEFAULT

'Active';

d)

ALTER TABLE students ALTER COLUMN status SET

DEFAULT 'Active';

5.

Which query ensures that the 'age' column in the 'students'

table cannot have null values?

a)

ALTER TABLE students SET NOT NULL (age);

b)

ALTER TABLE students MODIFY age NOT NULL;

c)

ALTER TABLE students ALTER COLUMN age SET NOT

NULL;

d)

ALTER TABLE students UPDATE age SET NOT NULL;

6.

Which normalization form ensures that all non-key attributes

are fully functional dependent on the primary key?

a)

First Normal Form (1NF)

b)

Second Normal Form (2NF)

c)

Third Normal Form (3NF)

d)

Boyce-Codd Normal Form (BCNF)

7.

Which query removes the foreign key constraint from the

'student_id' column in the 'enrollments' table?

a)

ALTER TABLE enrollments DROP FOREIGN KEY

(student_id);

b)

ALTER TABLE enrollments REMOVE FOREIGN KEY

(student_id);

c)

ALTER TABLE enrollments DROP CONSTRAINT

FOREIGN KEY (student_id);

d)

ALTER TABLE enrollments DROP CONSTRAINT

student_id;

8.

Which query creates a table 'courses' with a unique constraint

on the 'course_code' column?

a)

CREATE TABLE courses (course_id INT, course_name

VARCHAR(100), course_code VARCHAR(20) UNIQUE);

b)

CREATE TABLE courses (course_id INT, course_name

VARCHAR(100), UNIQUE course_code VARCHAR(20));

c)

CREATE TABLE courses (course_id INT, course_name

VARCHAR(100), ADD UNIQUE (course_code)

VARCHAR(20));

d)

CREATE TABLE courses (course_id INT, course_name

VARCHAR(100), SET UNIQUE (course_code));

9.

Which normalization form ensures that there are no transitive

dependencies in a table?

a)

First Normal Form (1NF)

b)

Second Normal Form (2NF)

c)

Third Normal Form (3NF)

d)

Boyce-Codd Normal Form (BCNF)

10.

Which query adds a check constraint to ensure the 'age'

column in the 'students' table is always greater than 18?

a)

ALTER TABLE students ADD CONSTRAINT age_check

CHECK (age > 18);

b)

ALTER TABLE students SET CONSTRAINT CHECK (age

> 18);

c)

ALTER TABLE students ADD CHECK (age > 18);

d)

ALTER TABLE students MODIFY CHECK (age > 18);