UNIQUE constraint

  • hello

    can i use UNIQUE constraint that do not calculate the NULL values in the column

  • On 2005, not easily. You can create an indexed view and put a unique clustered index on that, or you can define a calculated column and put the constraint on that.

    On 2008 it's much easier - use a filtered unique index

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Not with SQL Server 2005. You can create an indexed view on the table that will have a unique constraint and will not include NULL value, but I have to admit that when I tried using it in the past I gave it up because of all the set option that it required. By the way with SQL Server 2008 you can have where clause for indexes, so at that version making sure that some values will be unique and other won't, won't be a problem.

    Adi

    --------------------------------------------------------------
    To know how to ask questions and increase the chances of getting asnwers:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply