Systems Engineering and RDBMS

  • Click Here for Decipher's Homepage


  • Categories

  • Questions?

    Please send your wish list of things that you would like us to write about or if you have suggestions to help improve this blog site. You can send all questions/suggestions to: Blog Support
  • Archives

  • Blog Stats

    • 7,606,458 Views

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”

  1. […] 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 […]

  2. local seo guide 2013

    Unique Index « Systems Engineering and RDBMS

Sorry, the comment form is closed at this time.