Add Id to the cokumn

  • Hi,

    I have a table which has more than 400.000 rows.

    I need that one of it's columns named ID become identity.

    The column has integer values and i want to add the identity property to the column (1,1).

    How can i do this by t-sql?

    Thank you

  • 1. create a new table with the columns setup correctly, you can use your current table as a template.

    2. copy the data across (select into ) from old table to new.. the id will update then

  • Maybe in my case it is not necessary.

    This is the problem:

    I have created a table named TempImport which imports data using bulk insert.

    This TempImport is an empty table and every time before i load it with new data i drop the table and recreate a new one empty.

    It's only a temporary table that i rename (to become a normal table) after it is all loaded

    Maybe if i create the temptable already with the identity property in the comun (id) and before i do the insert by bulk insert, if i specify the set identity_insert = on and after the the bulk of the data put the set identity_insert = off my problem is solved.

    What do you think?

  • sounds spot on.

  • didn't undestood your answer 🙂

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

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