SQL Server标识列值从0而不是1开始 [英] SQL server identity column values start at 0 instead of 1

查看:210
本文介绍了SQL Server标识列值从0而不是1开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个奇怪的情况,即使TABLE CREATE具有IDENTITY(1,1),数据库中的某些表的ID也从0开始. 对于某些表是这样,但对于其他表则不是. 它一直有效到今天.

我尝试过重置身份列:

DBCC CHECKIDENT (SyncSession, reseed, 0);

但是新记录从0开始. 我已经尝试过对所有表执行此操作,但是某些表仍从0开始,而某些则从1开始.

有指针吗?

(我正在使用带有高级服务的SQL Server Express 2005)

解决方案

来自 DBCC CHECKIDENT

DBCC CHECKIDENT ( table_name, RESEED, new_reseed_value )

如果未将任何行插入到 自创建以来的表格,或全部 行已通过使用删除 TRUNCATE TABLE语句,第一个 运行DBCC之后插入的行 CHECKIDENT使用new_reseed_value作为 身份.否则,下一行 插入使用new_reseed_value + 当前的增量值.

因此,这对于空表或被截断的表是预期的.

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 others. It has worked until today.

I've tried resetting identity column:

DBCC CHECKIDENT (SyncSession, reseed, 0);

But new records start with 0. I have tried doing this for all tables, but some still start from 0 and some from 1.

Any pointers?

(i'm using SQL Server Express 2005 with Advanced Services)

解决方案

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.

这篇关于SQL Server标识列值从0而不是1开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆