Adding IDENTITY field to large table

  • Hi there ... What would the ideal method of adding an Identity field into a large table be, taking into account that a simple

    ALTER TABLE <TableName> ADD <IdField> INT IDENTITY causes a time-out ... Ideas, anyone?

  • Doesn't anybody have any pointers on this?

  • not an ideal solution, but a more long winded approach would be:

    --create a new, empty table copied from the original table structure

    --add the identity field to this new table

    --copy all the data from the original table into the new table

    --bin the original table

    --rename the new table

    I don't know why you get a timeout in the first place though ..

  • Steve, you might want to give us all time to wake up, read email etc.

    Do you have something else accessing the table?

    Andy

    http://qa.sqlservercentral.com/columnists/awarren/

  • Don't know why you get timeout either but I agree with planet115's answer. Another alternative is to bcp out, create new table and bcp back in. I have done copies both ways in the past with large tables (not with identity though).

    Edited by - davidburrows on 07/02/2003 06:27:53 AM

    Far away is close at hand in the images of elsewhere.
    Anon.

  • I'll go with the BCP suggestion of DavidBurrows.

  • Hey guys - thanks for the advice and my apologies on getting impatient 🙂

    Turns out that the components being used to alter the table had a hardcoded timeout time. This has now been fixed and the timeout extended.

    See ya'll later!

Viewing 7 posts - 1 through 6 (of 6 total)

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