Auto increment primary key in SQL Server Management Studio 2012

前端 未结 11 1062
谎友^
谎友^ 2020-11-22 10:11

How do I auto increment the primary key in a SQL Server database table, I\'ve had a look through the forum but can\'t see how.

11条回答
  •  难免孤独
    2020-11-22 11:05

    Make sure that the Key column's datatype is int and then setting identity manually, as image shows

    enter image description here

    Or just run this code

    -- ID is the name of the  [to be] identity column
    ALTER TABLE [yourTable] DROP COLUMN ID 
    ALTER TABLE [yourTable] ADD ID INT IDENTITY(1,1)
    

    the code will run, if ID is not the only column in the table

    image reference fifo's

提交回复
热议问题