Bulk Update???

  • Hi All,

    I have a table with more than 50 Million records.

    I am changing a PK column into identity.

    First I am droping all indexes and constraints then script to change datatype.

    Even after 5 hours, process is not complete.

    Can you suggest me some solution.

    Thanks.

  • 50 millions rows of data is not really that much data. it sounds like you are being blocked. exclusive schema locks, data , etc.

    this is my suggestion what you should do instead:

    1. script the table via SSMS with all the constraints and all indexes.

    2. modify the script to have a slightly different name, ie CREATE TABLE OriginalName_TMP

    3. modify the script to have the new identity field you want.

    4. create the table by running the modified script.

    5. rename the original table so people can no longer access it(sp_rename 'dbo.OriginalName','OriginalName_SAV')

    6. Insert the data into the table with the new structure (INSERT INTO OriginalName_TMP(ColumnList) .... SELECT ColumnList FROM OriginalName_SAV)

    7. rename the tmp table to the original name sp_rename 'dbo.OriginalName_TMP','OriginalName'

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • now that i had a sip of coffee, it's even easier:

    create the new table on the fly:

    --script out the constraints and indexes from the original table

    --create the new table instantly with the data and the identity column.

    SELECT

    identity(bigint,1,1) AS NewColumnName,

    ColumnList

    INTO OriginalName_TMP

    FROM OriginalName

    --rename the original

    EXECUTE sp_rename 'dbo.OriginalName','OriginalName_SAV'

    --rename the new table to teh right name

    EXECUTE sp_rename 'dbo.OriginalName_TMP','OriginalName'

    --modify the constraint script to have unique names for the new table and run them

    ALTER TABLE ADD CONSTRAINT UQ_...

    CREATE INDEX....

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

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

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