Add a column to existing table and uniquely number them on MS SQL Server

前端 未结 8 1255
暖寄归人
暖寄归人 2020-12-04 08:16

I want to add a column to an existing legacy database and write a procedure by which I can assign each record a different value. Something like ad

相关标签:
8条回答
  • 2020-12-04 08:50

    This will depend on the database but for SQL Server, this could be achieved as follows:

    alter table Example
    add NewColumn int identity(1,1)
    
    0 讨论(0)
  • 2020-12-04 08:50

    Depends on the database as each database has a different way to add sequence numbers. I would alter the table to add the column then write a db script in groovy/python/etc to read in the data and update the id with a sequence. Once the data has been set, I would add a sequence to the table that starts after the top number. Once the data has been set, set the primary keys correctly.

    0 讨论(0)
提交回复
热议问题