Solved

What does this T-SQL statement do exactly?

Posted on 2007-11-26
2
641 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Turn Insights into Action

Communication across every corner of your business is essential to increase the velocity of your application delivery and support pipeline. Automate, standardize, and contextualize your communication processes with xMatters.

Question has a verified solution.

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

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 …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
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.

687 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