Adding an identity to an existing column

后端 未结 19 2384
温柔的废话
温柔的废话 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:08

    There isn't one, sadly; the IDENTITY property belongs to the table rather than the column.

    The easier way is to do it in the GUI, but if this isn't an option, you can go the long way around of copying the data, dropping the column, re-adding it with identity, and putting the data back.

    See here for a blow-by-blow account.

提交回复
热议问题