Solved

What does this T-SQL statement do exactly?

Posted on 2007-11-26
2
636 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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

777 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