Unique Key Combination

  • How would you enforce a unique key combination? For example, I have columns A and B in a table. I don't want A and B to be unique by themselves, but I want the combination of A and B in a single record to be unique. How would I do this? I've Googled for unique key combinations, but all I get are guides on setting up your basic unique keys, which isn't what I want. Does SQLServer support this?

    Regards,

    Chris

  • ALTER TABLE < Table name >

    ADD CONSTRAINT < Constraint Name > UNIQUE (ColA, ColB)

    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
  • Thanks!

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

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