Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IDENTITY ??

Status
Not open for further replies.

Komil13

Programmer
Joined
Sep 26, 2001
Messages
50
Location
US
how would i reset a identity using a sql statement or within a proc??
 
DBCC CHECKIDENT
( 'table_name' [, { NORESEED | {RESEED [, new_reseed_value]} }]
)

This example forces the current identity value in the jobs table to a value of 30.

USE pubs
GO
DBCC CHECKIDENT (jobs, RESEED, 30)
GO


Rick.
 
this doesn't work if there are records in the table ... is there any other way ??
 
My apologies it was something I didn’t have chance to test. Try using the DBCC statement after running the function 'SET IDENTITY_INSERT tablename ON' it might then work. I have not had chance to test this also.

You will need to run 'SET IDENTITY_INSERT tablename OFF' afterwards.

If this doesn't work can you explain what you are trying to achieve in more detail.

Rick.
 
Read about "DBCC CHECKIDENT" in SQL Books Online. The article explains how to reset seed values under certain conditions such as having data in the table.

SQL Server documentation can also be found at...

Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top