Auto increment primary key in SQL Server Management Studio 2012

前端 未结 11 1060
谎友^
谎友^ 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 10:59

    You can use the keyword IDENTITY as the data type to the column along with PRIMARY KEY constraint when creating the table.
    ex:

    StudentNumber IDENTITY(1,1) PRIMARY KEY
    

    In here the first '1' means the starting value and the second '1' is the incrementing value.

提交回复
热议问题