Discussion on:

10
Comments

Join the conversation!

Follow via:
RSS
Email Alert
I have a 16,449 rows table with a primary key which started seeded at 1 with increment of 1.
I add 2 rows to make it 16,451. Then I delete these 2 last rows I added.
dbcc checkident (table) yields,
Checking identity information: current identity value '16451', current column value '16451'.

I thought I should get current identity value '16451', current column value '16449'.
0 Votes
+ -
Contributr
I apologize for the confusion because the terminology does imply what you've inferred. However, I checked with expert Francisco Tapia and he confirmed the following for me:
CHECKIDENT returns the last identity value, even if it's no longer in the table -- so that's what I meant by "current value." He suggests you take a look at scope_identity, although, again, it won't tell you if a record's been deleted.
0 Votes
+ -
IDENTITY columns
sqllion 20th Aug 2011
All features of SQL Server IDENTITY property of columns. And a handy procedure to monitor all Identity columns. http://www.sqllion.com/2011/08/identity-in-sql/
0 Votes
+ -
Contributr
Thank you!
ssharkins@... 22nd Jul 2008
It's always great to hear such a nice response. I truly appreciate it. Thank you.
I have used IDENTITY often (much to the disappointment of Joe Celko), and have one question. How would you fill in holes in an IDENTITY column?
Say I have been using the column as a generic Primary Key generator for a BI application. Some old data gets deleted, foreign keys are also deleted, etc.

Now I have holes that I would like to reuse; can reseed be used to address this somehow? I???m wondering if the error produced by attempting to use an IDENTITY value that already exist could be caught in a TRY / CATCH process and re-attempted somehow. Any idea?
0 Votes
+ -
Contributr
Personally, I wouldn't reuse deleted identity values. If some business rule requires a complete list of consecutive values you have a few choices:

1.) Rethink the business rule (my personal favorite). A lot of times these rules are unnecessary once you analyze their origin and use.
2.) Use a calculated column (not sure you can do this with a cc) or a sp to generate the numbers instead of using the identity property.
3.) Don't delete records. Flag them as deleted, but don't actually remove them. Accommodate them in your queries and views.
0 Votes
+ -
Thanks for the response. It sounds like IDENTITY is still not the answer / replacement compared to the various approaches that have been used historically in database design.

With data Warehouses, keeping expired or "replaced" data is not viable when resources are a concern.
For more information on Identifying and listing all the IDENTITY columns present in a given database with filtering option available for specific tables, refer the below link:
http://www.sqllion.com/2011/08/identity-in-sql/
0 Votes
+ -
Useful, Thanks
epsilonv 24th Aug 2010
I had to execute the procedure twice for each table, first it set the current column and next time it set the current identity. I did it through Visual Studio though so that might have something to do with it.
Keyboard Shortcuts:
Prev
Next
Toggle
Join the conversation
Formatting +
BB Codes - Note: HTML is not supported in forums
  • [b] Bold [/b]
  • [i] Italic [/i]
  • [u] Underline [/u]
  • [s] Strikethrough [/s]
  • [q] "Quote" [/q]
  • [ol][*] 1. Ordered List [/ol]
  • [ul][*] · Unordered List [/ul]
  • [pre] Preformat [/pre]
  • [quote] "Blockquote" [/quote]

Join the TechRepublic Community and join the conversation! Signing-up is free and quick, Do it now, we want to hear your opinion.