简体   繁体   中英

SQL Server 2008, add 'x' to auto increment value

I am using SQL Server 2008 and what I am trying to do is:

update Daily set ReferenceNo = ReferenceNo + 100000

I can't do this as this is field is as follows: [ReferenceNo] [bigint] IDENTITY(1,1) NOT NULL,

If I try to change remove the auto increment and save the table to do what I need to do I get the following error:

在此输入图像描述

Is there a way I can do this without dropping the table?

It's safety feature of SQL Server Management Studio - but you can turn it off :-)

Go to Tools > Options and then:

在此输入图像描述

After you've disabled that option, you should be able to do what you want to do in the visual designer.

I've figured it out, for anyone else who has this problem, do the following:

In SQL Server 2008, go to Tools > Options > Designers > Table and Database Designers > Prevent saving changes that require table re-creation. Turn this option off and you will be able to save the tables again.

The error reveals that the IDENTITY column is ALSO your clustering key.

Check out this answer to a previous question.

It gets complicated due to it being an IDENTITY column, which by design cannot be UPDATEd.
Because you're updating a clustering key, the data is in fact deleted and re-inserted. Given that it has to rewrite all the data, it's no more trouble to just recreate the table - triggers, synonyms, functions, schema-bound views, and foreign keys aside - that is.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM