Archive for July 22nd, 2008
How To Stop Ajax Post Back when A button contains OnClick() and onclientclick events
Posted by rameshch on July 22, 2008
Posted in Ajax and javaScript | Leave a Comment »
when IDENTITY columns reaching the Limit
Posted by rameshch on July 22, 2008
The IDENTITY columns are auto incrementing columns provided by SQL Server. There can only be one IDENTITY column per table. we just have to provide a base value, and an increment value, and SQL Server will take care of incrementing this column automatically .To make sure they are not reaching the limit of their base data type. For example, if we created an IDENTITY column of smallint data type, its values can go up to 32767. If we try to insert anymore rows, we will get the following error:
Server: Msg 8115, Level 16, State 1, Line 1
Arithmetic overflow error converting IDENTITY to data type smallint.
Arithmetic overflow occurred.
This procedure below, displays information about all
IDENTITY columns in the database, and shows you the percentage of IDENTITY values already used. If we are seeing any IDENTITY columns that have used up 80% or more values, then we need to start thinking about it. we could customize this procedure to automatically email us or log an error if there are any IDENTITY columns that are nearing the limit. we could also schedule this procedure as an SQL Agent job, so that it checks these columns regularly. Any new IDENTITY columns added to the database will automatically get picked up by this query.
CREATE PROC dbo.CheckIdentities
AS
BEGIN
SET NOCOUNT ON
SELECT QUOTENAME(SCHEMA_NAME(t.schema_id)) + '.' + QUOTENAME(t.name) AS TableName,
c.name AS ColumnName,
CASE c.system_type_id
WHEN 127 THEN 'bigint'
WHEN 56 THEN 'int'
WHEN 52 THEN 'smallint'
WHEN 48 THEN 'tinyint'
END AS 'DataType',
IDENT_CURRENT(SCHEMA_NAME(t.schema_id) + '.' + t.name) AS CurrentIdentityValue,
CASE c.system_type_id
WHEN 127 THEN (IDENT_CURRENT(SCHEMA_NAME(t.schema_id) + '.' + t.name) * 100.) / 9223372036854775807
WHEN 56 THEN (IDENT_CURRENT(SCHEMA_NAME(t.schema_id) + '.' + t.name) * 100.) / 2147483647
WHEN 52 THEN (IDENT_CURRENT(SCHEMA_NAME(t.schema_id) + '.' + t.name) * 100.) / 32767
WHEN 48 THEN (IDENT_CURRENT(SCHEMA_NAME(t.schema_id) + '.' + t.name) * 100.) / 255
END AS 'PercentageUsed'
FROM sys.columns AS c
INNER JOIN
sys.tables AS t
ON t.[object_id] = c.[object_id]
WHERE c.is_identity = 1
ORDER BY PercentageUsed DESC
END
—————————————————————————
EXEC dbo.CheckIdentities
GO
Posted in SQL | Leave a Comment »