?
Solved

What does this T-SQL statement do exactly?

Posted on 2007-11-26
2
Medium Priority
?
642 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 750 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 750 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Suggested Courses

801 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