Sunday, January 23, 2011

Best approach to change from identity(1,1) to identity(1,5)

i have some big tables with several million records and want to change the identity(1,1) to identity(1,5). what would be the best way to do that?

  • No answer yet?

    i see a way like this on a in place migration:

    SELECT *
    INTO Backup_Table
    FROM SOURCE_Table
    GO
    DROP Source_Table
    GO
    CREATE Source_Table (SerialNo IDENTITY(1,5) NOT NULL, ...)
    GO
    INSERT Source_Table(*)
    SELECT *
    FROM Backup_Table
    GO
    

    This has to be done for all the tables in a database.

    What do you think?

    Ice : On this approach one have to recreate all the constraints and indexes for new... The better way is to get a full-SQL-script from the table and change the Value of identity-step from 1 to 5 with an editor (search & replace). But how to restore the data?
    From Ice

0 comments:

Post a Comment