Unique Index
Posted by decipherinfosys on February 16, 2007
This is another one of those small things that people run into when porting over their application from Oracle to SQL Server/DB2 LUW. A unique index on a column in Oracle allows multiple NULL enteries. That is not true though in the case of SQL Server and DB2 LUW. In SQL Server and DB2 LUW, you can have only one single NULL value in the unique index and in the case of covered indexes (indexes on more than one column), you can have only one unique set and NULL is counted as a value for the purposes of a UNIQUE INDEX.
So, for an example…in SQL Server and in DB2 LUW:
create table test (col3 int, col4 int);
create unique index test1 on test (col3, col4);
1 null -> unique
2 null -> unique
2 null -> duplicate –> will give an error
null null -> unique
null null -> duplicate –> will give an error
null 1 -> unique.
2 Responses to “Unique Index”
Sorry, the comment form is closed at this time.
Multiple NULL values in a Unique index in SQL Server/DB2 LUW « Systems Engineering and RDBMS said
[…] from Oracle v9.2.0.5 to SQL Server 2005, he ran into the same UNIQUE index issue as we had blogged before. Since that was a major requirement by the client, this project needed to support having multiple […]
local seo guide 2013 said
local seo guide 2013
Unique Index « Systems Engineering and RDBMS