Adding an identity to an existing column

后端 未结 19 2095
温柔的废话
温柔的废话 2020-11-21 13:16

I need to change the primary key of a table to an identity column, and there\'s already a number of rows in table.

I\'ve got a script to clean up the IDs to ensure

19条回答
  •  自闭症患者
    2020-11-21 14:09

    There is cool solution described here: SQL SERVER – Add or Remove Identity Property on Column

    In short edit manually your table in SQL Manager, switch the identity, DO NOT SAVE changes, just show the script which will be created for the changes, copy it and use it later.

    It is huge time saver, because it (the script) contains all the foreign keys, indices, etc. related to the table you change. Writting this manually... God forbid.

提交回复
热议问题