Web Analytics Made Easy - Statcounter
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


Discover more from Technology with Vivek Johari

Subscribe to get the latest posts sent to your email.

By vivekjohari

I am currently working as a Senior Database Professional and have around 18 years of experience in database. Degree:- Master Degree in Computer(MCA) Certification course in Data Science & Machine Learning from Indian Institute of Technology (IIT), Delhi Work experience:- Designing of the database. Database Optimization. Writing Complex Stored Procedures,Functions,Triggers etc. Designing and developing SSIS & DTS packages. Designing SQL Reports using SSRS. Database Server Maintenance. Certification:- MCTS: DA-100: Analysing Data with Microsoft Power BI MCTS: DP-300: Administering Relational Databases on Microsoft Azure Microsoft certified Sql DBA in Sql server 2008 (MCTS). Microsoft certified BI professional in Sql server 2008 (MCTS). Oracle certified profession DBA in ORACLE 10g (OCP) certified profession DBA in ORACLE 9i (OCP) My other publication Technical Blog:- Technologies with Vivek Johari Guest Author and Blogger at sqlservercentral.com

31 thought on “Answer – Objective Question (How many Null values in an unique constraint can be inserted in SQL Server)”
  1. … [Trackback]

    […] Here you can find 34538 additional Information on that Topic: techmixing.com/2014/04/answer-objective-question-how-many-nu.html […]

  2. … [Trackback]

    […] There you can find 39997 more Information on that Topic: techmixing.com/2014/04/answer-objective-question-how-many-nu.html […]

Leave a Reply

Discover more from Technology with Vivek Johari

Subscribe now to keep reading and get access to the full archive.

Continue reading