|
Hey all Just want to run something past you all... The other day we had an issue with an application that basically maxed out the 2.1 billion+ limit in just a few hours on a identity (int) column. I was lucky enough that this table was a staging table can could be truncated. Problem solve and application fixed. My question is: Do you monitor on a regular basis the current identity field for any given table. I so how do you achieve this. As when I ran a DBCC CHECKIDENT on this particual column it took over 5 minutes. Thanks JL
(comments are locked)
|
|
IDENT_CURRENT is your friend :) Edit -> Wow, that was really embarrasing. I wrote a proc a few years back to gather those stats, and it was huge. Now it's eminently simple. I've just written it here as a multi-statement function, but it could just as easily be an in-line function. I really hope no-one saw this post before I edited it!! Ok, here's another one (just a plain SELECT), that gives you the maximum value for integer and numeric / decimal columns. Note that it doesn't go all the way up to the limit on numeric and decimal columns, because POWER() epic fails when raising 10 to the power of 29 or more, and gets the wrong value on 10 ^ 28. Thanks Matt... I can post you first question if you like? In your option you do this?
Jul 13 '10 at 01:45 PM
sp_lock
I do something similar, but manually. One extension I would make is to modify it so that it works out what the full range of the column is based on it's data type, and shows a percentage of how far the table is through it's identity range, and then introduce a parameter to the function to show identity rows above that threshold, or something...
Jul 13 '10 at 01:49 PM
Matt Whitfield ♦♦
@Matt Whitfield This is a very useful script, I am so glad that I ran into reading this post! I also have a question which I wanted to ask for a long time: what is the difference between ident_current('the_table') and the value in the last_value column of the sys.identity_columns view corresponding to the same table?
Jul 13 '10 at 01:52 PM
Oleg
@Oleg - IDENT_CURRENT will return the IDENT_SEED if there is no last value... to be honest, using last_value would probably be a better plan...
Jul 13 '10 at 02:03 PM
Matt Whitfield ♦♦
@Matt Whitfield Thank you, it is good to know about ident_seed in place of lacking last value. Before, I played with inserts/rollbacks trying to find a situation when they are out of sync (so I could figure out what is the difference), but it never happened.
Jul 13 '10 at 02:29 PM
Oleg
(comments are locked)
|

