How much is left until the Identity Column reaches its Max Value?

3 min readApr 30, 2024

This code provides insight into the current values of identity columns in the database and calculates the percentage of their usage relative to their maximum possible value.

object_schema_name (object_id) SchemaName,
object_name (ic.object_id) as TableName,
ic .name as ColumnName,
convert (bigint, isnull(ic.last_value, 0)) as LastValue,
case when = 'tinyint' then 255
when = 'smallint' then 32767
when = 'int' then 2147483647
when = 'bigint' then 9223372036854775807
end as…




I am writing about Sql Server, Elasticsearch and Python. İ am an Database Administrator on SQL Server and Elasticsearch more than 5+ years.