SQL Questions and Answers – SQL Constraints

This set of SQL Multiple Choice Questions & Answers (MCQs) focuses on “SQL Constraints”.

1. SQL constraints are rules used to limit the type of data that is entered in a table.
a) True
b) False
View Answer

Answer: a
Explanation: SQL constraints are the rules which are used to limit the type of data that is entered in a table. They are used to maintain the integrity and accuracy of the data present inside the table.

2. How many types of constraints are present in SQL?
a) 4
b) 5
c) 7
d) 6
View Answer

Answer: c
Explanation: In SQL, there are 7 types of constraints – UNIQUE, NOT NULL, CHECK, PRIMARY KEY, FOREIGN KEY, DEFAULT and INDEX.

3. In SQL, constraints can be divided into which of the following level?
a) Database level
b) Row level
c) Table level
d) Data level
View Answer

Answer: c
Explanation: In SQL, constraints can be divided into two types – Table level and Column level. The table level constraints are used to limit whole table data and the column level constraints are used to limit the column data.
advertisement
advertisement

4. Which of the following is a constraint in SQL?
a) Candidate Key
b) Foreign Key
c) Alternate Key
d) Super Key
View Answer

Answer: b
Explanation: In SQL, Foreign key is a constraint used to join two different tables. It is used to restrict those actions or data which would destroy the link between the two tables.

5. Which of the following statement can be used to apply column level constraints to a table in SQL?
a)

CREATE TABLE TABLE_NAME(
column1 data_type(SIZE) CONSTRAINT,
column2 data_type(SIZE) CONSTRAINT,
...
columnn data_type(SIZE) CONSTRAINT);

b)

advertisement
CREATE TABLE TABLE_NAME(
CONSTRAINT column1 data_type(SIZE),
CONSTRAINT column2 data_type(SIZE),
...
CONSTRAINT columnn data_type(SIZE));

c)

advertisement
CREATE TABLE TABLE_NAME (
column1 data_type(SIZE),
column2 data_type(SIZE),
...
columnn data_type(SIZE),
CONSTRAINT (column1,column2…columnn));

d)

CREATE TABLE TABLE_NAME(
column1 data_type(SIZE),
column2 data_type(SIZE),
...
columnn data_type(SIZE));
View Answer
Answer: a
Explanation: In SQL, the syntax used to apply column level constraint to a table is –

CREATE TABLE TABLE_NAME(
column1 data_type(SIZE) CONSTRAINT,
column2 data_type(SIZE) CONSTRAINT,
...
columnn data_type(SIZE) CONSTRAINT);

The constraint which is to be applied at the column is placed after the datatype used by the column.

6. In SQL, which of the following constraint cannot be applied at the table level?
a) UNIQUE
b) PRIMARY KEY
c) CHECK
d) NOT NULL
View Answer

Answer: d
Explanation: In SQL, the NOT NULL constraint cannot be applied at the table level. Constraints that can be applied at the table level are – UNIQUE, PRIMARY KEY, CHECK and FOREIGN KEY. The NOT NULL and DEFAULT constraints can be applied at the column level.

Sanfoundry Global Education & Learning Series – SQL.

To practice all areas of SQL, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.