为什么在SQL Server 2008 R2中设置当前身份值对我不起作用? [英] Why setting current identity value is not working for me in SQL Server 2008 R2?

查看:222
本文介绍了为什么在SQL Server 2008 R2中设置当前身份值对我不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用SQL Server 2008 R2.

I am working with SQL Server 2008 R2.

我有一个表seq_audit,其中有一个标识列.这是表的定义:

I have a table seq_audit which has an identity column. This is the definition of the table:

CREATE TABLE [dbo].[seq_audit]
(
    [id] [bigint] IDENTITY(1,1) NOT NULL,
    [value] [bit] NULL,

    PRIMARY KEY CLUSTERED ([id] ASC)
          WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, 
                IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, 
                ALLOW_PAGE_LOCKS  = ON, FILLFACTOR = 90) ON [PRIMARY]
) ON [PRIMARY]

该表为空,之前从未有任何行.

The table is empty and never has had any rows in it before.

要检查其当前身份值,我运行了以下命令:

To check its current identity value, I ran this command:

DBCC CHECKIDENT (seq_audit, NORESEED) 
GO

这是我得到的结果:

检查身份信息:当前身份值'NULL',当前 列值"NULL". DBCC执行完成.如果DBCC打印错误 消息,请与系统管理员联系.

Checking identity information: current identity value 'NULL', current column value 'NULL'. DBCC execution completed. If DBCC printed error messages, contact your system administrator.

我想将其当前身份值设置为15953711.所以我运行了以下命令:

I want to set its current identity value to 15953711. So I ran this command:

DBCC CHECKIDENT (seq_audit, RESEED, 15953711)
GO

这是我得到的结果:

检查身份信息:当前身份值'NULL',当前 列值"15953711". DBCC执行完成.如果印有DBCC 错误消息,请与系统管理员联系.

Checking identity information: current identity value 'NULL', current column value '15953711'. DBCC execution completed. If DBCC printed error messages, contact your system administrator.

我认为它可以正常工作,因此我通过运行以下命令再次检查其当前身份:

I thought it worked so I again check its current identity by running this command:

DBCC CHECKIDENT (seq_audit, NORESEED) 
GO

但是我没有期望得到的结果:

But I was not expected the result I get:

检查身份信息:当前身份值'NULL',当前 列值"NULL". DBCC执行完成.如果DBCC打印错误 消息,请与系统管理员联系.

Checking identity information: current identity value 'NULL', current column value 'NULL'. DBCC execution completed. If DBCC printed error messages, contact your system administrator.

因此,当前标识值的设置不起作用.为什么?我在这里做什么错了?

So somehow the setting of current identity value is not working. Why? What am I doing wrong here?

推荐答案

这是由于您的表为空而引起的.尝试添加单个记录,然后一切正常.我已经尝试过了,可以确认它是否有效.

This is caused by the fact that your table is empty. Try adding a single record and then everything will work. I have tried this and can confirm that it works.

此外,如果使用SQL Server Management Studio,则可以使用设计功能来更改种子值.并手动添加和删除记录.

Also, if you use SQL Server Management studio you can use the design feature to change the seed values. and manually add and delete records.

这篇关于为什么在SQL Server 2008 R2中设置当前身份值对我不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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