Add a unique constraint to an existing table

  • Hi, I have a table that includes columns

    Firstname, lastname and Birthdate. How do I add a unique constraint on these three fields?

    Thanks!!

  • ALTER TABLE SomeTable ADD CONSTRAINT UQ_Firstname_lastname_Birthdate UNIQUE (Firstname,lastname,Birthdate)

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • So people with the same name never share a birthday?

    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
  • Yes, that is correct.

  • Thanks!

Viewing 5 posts - 1 through 4 (of 4 total)

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