setting identify field off


I'm trying to update an ID field that is set as an identifying field.  I tried using the query below, but get an error that says,"cannot update identity column 'ID'  Can someone help me with this?

UPDATE prospects
set ID = 145191
where id = 145540
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott PletcherSenior DBACommented:
Unfortunately, SQL does not allow UPDATE of the value of an IDENTITY column.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Scott PletcherSenior DBACommented:
You can do an INSERT and DELETE to get the same net effect (if you can serialize the table temporarily; otherwise someone else could insert into it and "steal" your identity number; if you know the table is not being INSERTed to, you can leave out the serialize / tablelock):



DBCC CHECKIDENT('dbo.prospects', RESEED, 145190)

INSERT INTO dbo.prospects (col1, col2) --, ...) --all cols EXCEPT ID
SELECT col1, col2 --, ...
FROM dbo.prospects WITH (TABLOCKX)
WHERE ID = 145540


DELETE FROM dbo.prospects
WHERE ID = 145540

Open in new window

nmaranoAuthor Commented:
Thanks, I switched it to an insert,
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.