Solved

What does this T-SQL statement do exactly?

Posted on 2007-11-26
2
635 Views
Last Modified: 2008-02-01
select 'DBCC CHECKIDENT ('+''''+OBJECT_NAME(OBJECT_ID)+''''+',RESEED,'+convert(varchar(15), seed_value)+')' FROM SYS.IDENTITY_COLUMNS
0
Comment
Question by:ksfok
2 Comments
 
LVL 15

Accepted Solution

by:
dbbishop earned 250 total points
ID: 20354515
Not certain what the purpose is. It is generating a string that is executing DBCC CHECKIDENT for the identity column, and the RESEED option sets the seed back to whatever the original value was. However, as written, this only displays the string. The normal syntax for something like this would be:

DECLARE @SQL VARCHAR(8000)
SELECT @SQL = 'DBCC CHECKIDENT ('+''''+OBJECT_NAME(OBJECT_ID)+...

EXEC(@SQL)
0
 
LVL 25

Assisted Solution

by:imitchie
imitchie earned 250 total points
ID: 20355305
it looks like code to reset a test (or demo) database to a known state (reseeded auto increment numbers).  the code is generated, so that an administrator and eyeball it before running it.  A sample output would be

DBCC CHECKIDENT ('UniqueKeyHolderForSomeStoredProc',RESEED,1)
DBCC CHECKIDENT ('table_1_1977058079',RESEED,0)
DBCC CHECKIDENT ('table_1_2009058193',RESEED,0)
DBCC CHECKIDENT ('table_3_2041058307',RESEED,1001)
etc.
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how the fundamental information of how to create a table.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now