- /**************************************************************************************************************
- --脚本名称 : db_sequences_alert.sql
- --脚本作者 : 潇湘隐者
- --创建日期 : 2021-01-21
- ***************************************************************************************************************
- 脚本功能 : 检查数据库中的sequences的使用情况,如果sequences的当前值超过maximum_value的85%,
- 就应该采取措施处理。
- ***************************************************************************************************************
- 注意事项 : 暂无
- ***************************************************************************************************************
- 参考资料 : https://docs.microsoft.com/en-us/sql/relational-databases/system-catalog-views/sys-sequences-transact-sql?view=sql-server-ver15
- ***************************************************************************************************************
- 更新记录 : 2021-01-21 创建此脚本
- ***************************************************************************************************************/
-
- SELECT @@SERVERNAME AS [server_name]
- ,DB_NAME(DB_ID()) AS [database_name]
- ,SCHEMA_NAME(schema_id) AS [scheme_name]
- ,name AS [sequence_name]
- ,create_date AS [create_date]
- ,modify_date AS [modify_date]
- ,type_desc AS [type_desc]
- ,start_value AS [start_value]
- ,current_value AS [current_value]
- ,minimum_value AS [minimum_value]
- ,maximum_value AS [maximum_value]
- ,is_cycling AS [is_cycling]
- ,cache_size AS [cache_size]
- ,is_exhausted AS [is_exhausted]
- ,CASE WHEN increment >=1 THEN
- ROUND(CAST(current_value AS DOUBLE PRECISION)/CAST(maximum_value AS DOUBLE PRECISION)*100,2)
- ELSE
- ROUND(CAST(current_value AS DOUBLE PRECISION)/CAST(minimum_value AS DOUBLE PRECISION)*100,2)
- END AS [percent_usage(%)]
- FROM sys.sequences
- WHERE is_cycling =0
- ORDER BY [percent_usage(%)] DESC
- GO