Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1077661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:36:29+00:00 2026-05-16T21:36:29+00:00

I have a suite of database unit tests that were created. In order to

  • 0

I have a suite of database unit tests that were created. In order to replicate all of the tests on any machine I deploy out to there are scripts to drop the database and recreate it. The test will work for all of the unit tests except for the first test.

The reason the first test fails is that I am executing the “dbcc checkident” command before each test and resetting all of the identities in order to ensure that all of the identities are the same. On a new table that has never been inserted into and then has “dbcc checkident” ran against it the identity starts at 0 when inserted into instead of 1.

If I use some of the other built in commands to check the identity in a fresh table, they return 0 as the identity. The benefit for checking through “dbcc checkident” is that the identity comes back as ‘NULL’ if a row has never been inserted into it. Only “dbcc checkident” tells us through a print message and cannot easily be tested.

How can I verify that that I need to reset the identity or not through database commands without inserting a row, deleting it, then resetting just to avoid the identity from getting off on the first record?

Example of inserting into a table

Identity after inserting a row on a fresh table without running “dbcc checkident” and setting identity to 0 = 1

Identity after inserting a row on a fresh table and running “dbcc checkident” and setting identity to 0 = 0

Identity after inserting a row on an existing table thats been inserted into and running “dbcc checkident” and setting identity to 0 = 1

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T21:36:30+00:00Added an answer on May 16, 2026 at 9:36 pm

    To get around the identity insert problem with “dbcc checkident” on a new table, here’s what I did.

    Using the sys tables I was able to manually check the last identity value through sql. If the last identity was reset, it will change the last value to 0. On a new table that has never been inserted into the last identity will be null.

    Here is the code snippet we used. This will allow you to check the last identity without doing an insert, delete, reset identity.

    -- {0} is your table name
    -- {1} is your identity value of the reset
    
    IF EXISTS (SELECT null FROM sys.identity_columns WHERE OBJECT_NAME(OBJECT_ID) = '{0}' AND           last_value IS NOT NULL) 
        DBCC CHECKIDENT ({0}, RESEED, {1});
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a suite of system tests that uses Spring's JUnit runner, the database
I have a suite of web tests created for a web service. I use
I have multiple unit tests that have to connect to a MySQL Server to
I have a site that processes orders taken by phone into a SQL database.
I have an ASP.NET MVC2 site connecting to a MySQL database via DbLinq. There
We have a suite of programs that check for new versions at startup, and
Just wanted to run this by you all to see if there are any
I have a solution that uses EF Code First. I recently upgraded all my
A suite of integration services that use NServiceBus have been dropped in my lap
I have several suites of integration tests implemented in C#/NUNit. Each test suite is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.