Alter Table

  • Hello All

    I have a rather simple question that Iseem to have trouble doing. I need to add multiple Pri Key to pre-existing columns in a table. Cna someone give the correct syntax for this?

    Thanks in avance

  • You can only have one primary key on a table.

     

    You need to check BOL for UNIQUE columns. There are probabaly what you are after.


    ------------------------------
    The Users are always right - when I'm not wrong!

  • Although you can have only one PK, you can have multilple columns in your PK.

    ALTER TABLE [dbo].[Table] DROP CONSTRAINT [TablePK]

    GO

    ALTER TABLE [dbo].[Table] ADD CONSTRAINT [TablePK] PRIMARY KEY  CLUSTERED

     (

      [PK1],

      [PK2]

    &nbsp  ON [PRIMARY]

    GO

     

    Signature is NULL

  • You can also create multiple "Alternate" keys by using unique indexes.




    Gary Johnson
    Microsoft Natural Language Group
    DBA, Sr. DB Engineer

    This posting is provided "AS IS" with no warranties, and confers no rights. The opinions expressed in this post are my own and may not reflect that of my employer.

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

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