Click here to Skip to main content
15,888,000 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi,

I have table with one column as Identity column, if I delete a row number 6 which
has Identity column seed value as 6 then if insert a new row in the table then
how can I insert same number 6 in the identity column?

I tried in google but I could get it.
Please let me know.
Posted

You will have to use the SET IDENTITY_INSERT method

SQL
SET IDENTITY_INSERT OFF

INSERT INTO table1 (ID, Field1) VALUES (6,'test')

SET IDENTITY_INSERT ON


Hopefully this is just a one-time fix. I would not suggest having regular processes that do this.

Refer to http://msdn.microsoft.com/en-us/library/aa259221(v=sql.80).aspx[^]
 
Share this answer
 
if nr 6 is the last record and (re-)inserting data you can also use
SQL
DBCC CHECKIDENT (yourtable, reseed, 5)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900