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
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
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
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.
4. Which of the following is a constraint in SQL?
a) Candidate Key
b) Foreign Key
c) Alternate Key
d) Super Key
View Answer
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)
CREATE TABLE TABLE_NAME( CONSTRAINT column1 data_type(SIZE), CONSTRAINT column2 data_type(SIZE), ... CONSTRAINT columnn data_type(SIZE));
c)
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));
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
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.