Creating Unique Index on the column with the existing duplicates

  • Hi,

    Is there any way to "cheat" on SQL on creating a unique index/constraint for the column that already has duplicates?

    Let's say I do not care much that there are already some dups in the table (or even want to keep them) but at the same time I want to make sure it wont happen in the future?

    Thanks!

  • A index is either unique or it's not unique. To do what you want, you'll probably need a trigger, and it will hurt your insert/update performance.

    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
  • A partitioned table might allow you to do that, but not a regular table.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

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

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