Blog Post

Answer - Objective Question (How many Null values in an unique constraint can be inserted in SQL Server)

,

Question:- How many NULL value allowed in a column in which Unique constraint is defined in SQL Server?

Options:-

a) 1

b) 2

c) More than 1

Answer :- Option a) 1

In SQL Server, we can Insert only one null value in a column where we have defined the Unique Constraint.

For Example , suppose we made a table test_unique, whose script is given below:-

create table test_unique (id int unique)

Now we insert the following values in it.

insert into test_unique(id) values (1)

insert into test_unique(id) values (2)

insert into test_unique(id) values (NULL)

insert into test_unique(id) values (3)

Here we inserted one null value before inserting 3.

If we see the records in the table , it shows the following data.


Let try to insert another NULL value and see what error it gives.

insert into test_unique(id) values (NULL)

Then it will gives the following error


So, In SQL server we can insert only one NULL value in a column where Unique constraint is defined.

DMCA.com

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating