SQL Questions and Answers – SQL Default Constraint

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

1. Which of the following constraint is used to provide a default value to a column in SQL?
a) CHECK
b) DEFAULT
c) NOT NULL
d) PRIMARY KEY
View Answer

Answer: b
Explanation: The DEFAULT constraint is used to provide a default value to a column in SQL. It works when the user does not enter any value to the column on which the DEFAULT constraint is applied. The CHECK constraint is used to check the value entered in a table on the basis of a specified condition. The NOT NULL constraint is used to ensure that the data present in a column of a table is not empty. The PRIMARY KEY constraint is used to uniquely identify any value in a table.

2. Which of the following statement is used to apply the DEAFULT constraint to a column in SQL?
a)

CREATE TABLE TABLE_NAME DEFAULT (
column1 datatype VALUE,
column2 datatype VALUE,
...
columnn datatype VALUE);

b)

CREATE TABLE TABLE_NAME (
column1 datatype,
column2 datatype,
...
columnn datatype
DEFAULT (column1, column2,… columnn) VALUE);

c)

advertisement
advertisement
CREATE TABLE TABLE_NAME (
DEFAULT column1 datatype VALUE,
DEFAULT column2 datatype VALUE,
...
DEFAULT columnn datatype VALUE);

d)

CREATE TABLE TABLE_NAME (
column1 datatype DEFAULT VALUE,
column2 datatype DEFAULT VALUE,
...
columnn datatype DEAFULT VALUE);
View Answer
Answer: d
Explanation: In SQL, the statement that can be used to apply the DEFAULT constraint to a column is

advertisement
CREATE TABLE TABLE_NAME (
column1 datatype DEFAULT VALUE,
column2 datatype DEFAULT VALUE,
...
columnn datatype DEAFULT VALUE);

The DEFALUT constraint is followed by the value that has to be assigned to the column if it is left empty by the user.

advertisement

3. Which of the following statement can be used to apply the DEFAULT constraint on a column in an existing table?
a)

ALTER TABLE TABLE_NAME
ALTER column_name SET DEFAULT VALUE;

b)

ALTER TABLE TABLE_NAME
ALTER column_name DEFAULT VALUE;

c)

ALTER TABLE TABLE_NAME
column_name SET DEFAULT VALUE;

d)

ALTER TABLE TABLE_NAME
CHANGE column_name SET DEFAULT VALUE;
View Answer
Answer: a
Explanation: The statement that can be used to apply the DEFAULT constraint on a column in an existing table –

ALTER TABLE TABLE_NAME
ALTER column_name SET DEFAULT VALUE;

The ALTER command is used with the ALTER and the DEFAULT keyword to apply the DEFAULT constraint. Here, the column name and the value have to be specified along with the previously stated keywords.

4. Which of the following statement is used to delete the DEFAULT constraint from a column in an existing column?
a)

ALTER TABLE TABLE_NAME
ALTER DELETE DEFAULT;

b)

ALTER TABLE TABLE_NAME
ALTER DROP DEFAULT;

c)

ALTER TABLE TABLE_NAME
ALTER City DROP DEFAULT;

d)

ALTER TABLE TABLE_NAME
ALTER City DELETE DEFAULT;
View Answer
Answer: c
Explanation: The statement that can be used to delete the DEFAULT constraint from a column in an existing column is –

ALTER TABLE TABLE_NAME
ALTER City DROP DEFAULT;

The ALTER command is used with the ALTER and the DROP keyword to delete the constraint.

5. In SQL, the DEFAULT constraint can also be applied as a table level constraint.
a) True
b) False
View Answer

Answer: b
Explanation: In SQL, the DEFAULT constraint cannot be applied as a table level constraint as every column contains different types of values with different datatypes and only one default cannot be applied to all of them.

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.