SQL server identity column values start at 0 instead of 1

后端 未结 6 2009
孤城傲影
孤城傲影 2020-12-01 20:40

I\'ve got a strange situation with some tables in my database starting its IDs from 0, even though TABLE CREATE has IDENTITY(1,1). This is so for some tables, but not for ot

6条回答
  •  醉酒成梦
    2020-12-01 21:02

    From DBCC CHECKIDENT

    DBCC CHECKIDENT ( table_name, RESEED, new_reseed_value )
    

    If no rows have been inserted to the table since it was created, or all rows have been removed by using the TRUNCATE TABLE statement, the first row inserted after you run DBCC CHECKIDENT uses new_reseed_value as the identity. Otherwise, the next row inserted uses new_reseed_value + the current increment value.

    So, this is expected for an empty or truncated table.

提交回复
热议问题