This set of SQL Multiple Choice Questions & Answers (MCQs) focuses on “SQL Not Null”.
1. In SQL, which of the following constraint is used to ensure that the data present in a column of a table is not empty?
a) NULL
b) UNIQUE
c) NOT NULL
d) PRIMARY KEY
View Answer
Explanation: In SQL, the NOT NULL constraint is used to ensure that the data present in a table is not null. The UNIQUE constraint is used to ensure that a column always contains unique values. The PRIMARY KEY constraint is a mixture of both NOT NULL and UNIQUE constraint.
2. In SQL, a NULL value is the same as a zero value.
a) True
b) False
View Answer
Explanation: In SQL, a NULL value is not the same as a zero value or a value containing spaces. A null value is a field that has been left unfilled during the record creation.
3. In SQL, the NOT NULL constraint can be written as a table level constraint.
a) True
b) False
View Answer
Explanation: In SQL, the NOT NULL constraint can not be written as a table level constraint. It is always written as a column level constraint because it is not necessary to fill each information. If all the data needs to be not null, then we can place the constraint after each column name.
4. Which of the following statement is used to apply the NOT NULL constraint?
a)
CREATE TABLE TABLE_NAME ( column1 data_type NOT NULL, column2 data_type NOT NULL, ... columnn data_type NOT NULL);
b)
CREATE TABLE TABLE_NAME ( NOT NULL column1 data_type, NOT NULL column2 data_type, ... NOT NULL columnn data_type);
c)
CREATE TABLE TABLE_NAME ( column1 data_type, column2 data_type, ... columnn data_type, NOT NULL (column1, column2,..., columnn));
d)
CREATE TABLE TABLE_NAME NOT NULL ( column1 data_type, column2 data_type, ... columnn data_type);
Explanation: The statement used to apply the NOT NULL constraint is –
CREATE TABLE TABLE_NAME ( column1 data_type NOT NULL, column2 data_type NOT NULL, ... columnn data_type NOT NULL);
The NOT NULL constraint is added after the datatype of every column that does not want a null value.
5. Which of the following combination of statements can be used to add the NOT NULL constraint to an existing column?
a)
UPDATE TABLE_NAME SET column_name = <value> WHERE column_name IS NULL; & ALTER TABLE TABLE_NAME ALTER COLUMN column_name data_type NOT NULL;
b)
UPDATE TABLE_NAME SET column_name = <value> WHERE column_name IS NOT NULL; & ALTER TABLE TABLE_NAME ALTER COLUMN column_name data_type IS NULL;
c)
UPDATE TABLE_NAME SET column_name = <value>; & ALTER TABLE TABLE_NAME ALTER COLUMN column_name data_type NOT NULL;
d)
UPDATE TABLE_NAME SET column_name = <value> WHERE column_name IS NULL; & ALTER TABLE TABLE_NAME ALTER COLUMN column_name data_type;
Explanation: The combination of statements that can be used to add the NOT NULL constraint to an existing column is –
UPDATE TABLE_NAME SET column_name = <value> WHERE column_name IS NULL; & ALTER TABLE TABLE_NAME ALTER COLUMN column_name data_type NOT NULL;
First, we update the table so there is no NULL in any column. Then we alter the table to change the property of the column to add the NOT NULL constraint.
6. Which of the following statement can be used to remove the NOT NULL constraint from an existing column?
a)
ALTER TABLE TABLE_NAME ALTER COLUMN column_name data_type IS NULL;
b)
ALTER TABLE TABLE_NAME ALTER COLUMN column_name data_type NOT NULL;
c)
ALTER TABLE TABLE_NAME ALTER COLUMN column_name data_type;
d)
ALTER TABLE TABLE_NAME ALTER COLUMN column_name data_type NULL;
Explanation: The statement that can be used to remove the NOT NULL constraint from an existing column is –
ALTER TABLE TABLE_NAME ALTER COLUMN column_name data_type NULL;
To remove the NOT NULL constraint we use the ALTER command the modify the constraint of the required column and change it to NULL, so that it can accept null values.
7. Which of the following operator is used to test a column for empty values in SQL?
a) IS NULL
b) IS NOT NULL
c) NOT NULL
d) NULL
View Answer
Explanation: The IS NULL operator is used to test a column for empty values in SQL. The IS NOT NULL operator is used to test a column for non-empty values. NOT NULL is a constraint in SQL that can be applied to the column so that they do not accept null values.
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]