none
how to add identity property for existing column using T-SQL in sql server 2005

    Question

  •  how to add identity property for existing column using T-SQL in sql server 2005
    Satish
    Thursday, February 12, 2009 3:41 PM

Answers

  • You can't.
    You can only add the identity property when adding a new column, not add the property to an existing column.

    /Kenneth
    Thursday, February 12, 2009 4:05 PM
  • As Kenneth indicated, you can't just change an existing column to be in IDENTITY field.

    You must:
     
    1. Add a new IDENTITY column
    2. UPDATE any other tables that rely upon the existing column as a Foreign Key to use the new IDENTITY value.
    3. DROP the existing column from the table
    4. RENAME the new column to the same name as th dropped column.

    You may be only one person in the world, but you may also be the world to one person.
    Thursday, February 12, 2009 4:48 PM
    Moderator

All replies

  • You can't.
    You can only add the identity property when adding a new column, not add the property to an existing column.

    /Kenneth
    Thursday, February 12, 2009 4:05 PM
  • As Kenneth indicated, you can't just change an existing column to be in IDENTITY field.

    You must:
     
    1. Add a new IDENTITY column
    2. UPDATE any other tables that rely upon the existing column as a Foreign Key to use the new IDENTITY value.
    3. DROP the existing column from the table
    4. RENAME the new column to the same name as th dropped column.

    You may be only one person in the world, but you may also be the world to one person.
    Thursday, February 12, 2009 4:48 PM
    Moderator