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

HKN MZ
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.

select
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 t.name = 'tinyint' then 255
when t.name = 'smallint' then 32767
when t.name = 'int' then 2147483647
when t.name = 'bigint' then 9223372036854775807
end as…

--

--

HKN MZ

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