首页 > 数据库技术 > 详细

How to check sqlsever table data type identity status ?

时间:2020-02-16 21:14:02      阅读:72      评论:0      收藏:0      [点我收藏+]

Unlike in Oracle, sqlserver has an special data type in order by make identity growth. But what about if the number is exceed or approaching the limited ?

Yes. there will show an error like :

Arithmetic overflow error converting IDENTITY to data type int. Arithmetic overflow occurred.

In fact, we could monitor in any time..

Script:

select a.TABLE_NAME,a.COLUMN_NAME,a.DATA_TYPE,
(CASE a.DATA_TYPE when ‘int‘ then ‘limited between -2147483648 and 2147483647‘
when ‘bigint‘ then ‘limited between -9223372036854775808 and 9223372036854775807‘
when ‘smallint‘ then ‘limited between -32768 and 3767‘
when ‘decimal‘ then ‘limited between -10^38 and 10^38 - 1‘
END
) as "Description",
c.INCREMENT_VALUE,
c.LAST_VALUE as "current identity",
‘ ‘,
(CASE a.DATA_TYPE when ‘int‘ then 2147483647
when ‘bigint‘ then 9223372036854775807
when ‘smallint‘ then 3767
when ‘decimal‘ then 9999999999999999999999999999999
END
) as "MAX value"
from INFORMATION_SCHEMA.COLUMNS a inner join
SYS.objects b on a.TABLE_NAME=b.name
inner join SYS.IDENTITY_COLUMNS c on b.object_id=c.object_id
where COLUMNPROPERTY(object_id(a.TABLE_SCHEMA+‘.‘+a.TABLE_NAME), a.COLUMN_NAME, ‘IsIdentity‘) = 1
and a.COLUMN_NAME=c.name and a.table_name=OBJECT_NAME(c.OBJECT_ID)
order by a.TABLE_NAME


You could see like this following result.

技术分享图片

 

How to check sqlsever table data type identity status ?

原文:https://www.cnblogs.com/partition-liu/p/12317980.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!