How to add IDENTITY constraint after creating a table?

  • I had created table id as INT

    How to alter the table to add IDENTITY key

  • sharma (6/18/2008)


    I had created table id as INT

    How to alter the table to add IDENTITY key

    You will need to rebuild the table, i.e. you cannot just use an alter statement, you need to create a table with the identity property, copy the data (most likely you will want to set identity insert on), then delete the old table, and maybe sp_rename the table back. If you use Management Studio, it can create the script for this (open the table in the designer, ...). It will handle the simple cases, but in case it cannot do it, it can generate a "good enough" starting script.

    Regards,

    Andras


    Andras Belokosztolszki, MCPD, PhD
    GoldenGate Software

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

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