if exists (select * from sysobjects where id = object_id('dbo.sp_checkIdents') and sysstat & 0xf = 4) drop procedure dbo.sp_checkIdents GO CREATE PROCEDURE sp_checkIdents AS ----------------------------------------------------------------------------------------------------------------------------------------- -- Ricardo Pistarino -- 16-01-1998 -- Chequea todas las tablas que tienen un campo IDENTITY y corrige el valor -- Check every table having an IDENTITY column and fix the value. ----------------------------------------------------------------------------------------------------------------------------------------- DECLARE @tblname varchar(50) DECLARE CurIDTables CURSOR FOR SELECT sysobjects.name FROM syscolumns JOIN sysobjects ON syscolumns.ID = sysobjects.ID WHERE (status & 128) = 128 AND sysobjects.type = "U" OPEN CurIDTables FETCH NEXT FROM CurIDTables INTO @tblname WHILE (@@FETCH_STATUS = 0) BEGIN DBCC CHECKIDENT (@tblname) WITH NO_INFOMSGS FETCH NEXT FROM CurIDTables INTO @tblname END CLOSE CurIDTables GO