Index autoincrement for Microsoft SQL Server 2008 R2

后端 未结 2 416
失恋的感觉
失恋的感觉 2020-12-09 10:27

I created a new table in SQL Server 2008 R2, and i would like that the index is on autoincrement. How to do that? There is no identity data type; i selected int

2条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-09 11:15

    If your table definition is like this,

    ....,
    @id int,
    ....
    

    change it to,

    ....
    @id int identity(1,1),
    ....
    

    This will create an identity column which starts id with 1 and keeps increasing it by one(i.e. step) as each record in the table is inserted.

提交回复
热议问题