Solved

What does this T-SQL statement do exactly?

Posted on 2007-11-26
2
634 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
Comment Utility
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
Comment Utility
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

In this article—a derivative of my DaytaBase.org blog post (http://daytabase.org/2011/06/18/what-week-is-it/)—I will explore a few different perspectives on which week today's date falls within using Microsoft SQL Server. First, to frame this stu…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

743 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

17 Experts available now in Live!

Get 1:1 Help Now