UPDATE THE IDENTITY FIELD OF EXISTING RECORDS

  • Hello,

    I am trying to update the existing identity field as I want to increment the values and import into the same table in another database.

    I have tried turning the identity seed off, then back on and vice versa and it still will not let me update the fields.

    I have also removed the primary key. I am testing this is not a production db, below are the scripts I have attempted so far.

    SET IDENTITY_INSERT PO OFF

    UPDATE PO

    SET PONumber = PONumber + 3000

    SET IDENTITY_INSERT PO ON

    Can someone help me with some insight.

    Thank You

    Larry

  • duncanlarry (7/11/2014)


    Hello,

    I am trying to update the existing identity field as I want to increment the values and import into the same table in another database.

    I have tried turning the identity seed off, then back on and vice versa and it still will not let me update the fields.

    I have also removed the primary key. I am testing this is not a production db, below are the scripts I have attempted so far.

    SET IDENTITY_INSERT PO OFF

    UPDATE PO

    SET PONumber = PONumber + 3000

    SET IDENTITY_INSERT PO ON

    Can someone help me with some insight.

    Thank You

    Larry

    You can't just update the values like that. I would suggest you add your 3000 when you copy this to your other database.

    insert YourOtherDatabase.YourOtherTable

    select PONumber + 3000, YourOtherColumns

    etc...

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

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

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