Hi @Raj0125 , welcome to Microsoft Q&A forum.
Please find the Stored Procedure below:
//Updated the SP as per suggestion
CREATE PROCEDURE sp_ResetIdentityMax
AS
DECLARE @Table TABLE
(
TableName VARCHAR(50),
Id int identity(1,1)
)
--Getting only identity columns from all tables with dbo schema. You can add column name as well in where condition if you would like to
INSERT INTO @Table
select TABLE_NAME from INFORMATION_SCHEMA.COLUMNS where TABLE_SCHEMA = 'dbo' and COLUMNPROPERTY(object_id(TABLE_NAME), COLUMN_NAME, 'IsIdentity') = 1 and COLUMN_NAME like '%SKey' AND COLUMN_NAME NOT LIKE '%LOAD_SKey' AND COLUMN_NAME NOT LIKE 'GDP%'
DECLARE @max int, @SQL VARCHAR(MAX) , @TableName VARCHAR(100), @ColumnName varchar(100)
DECLARE @id int = 1
select @max = MAX(Id) from @Table
WHILE (@id <= @max)
BEGIN
SELECT @TableName = TableName FROM @Table WHERE Id = @id
--Resetting the column value to '1' for new records
DBCC CHECKIDENT(@TableName, RESEED,0);
SET @id = @id +1
END
Referenced Article: t-sql for loop to iterate through tables
Please let me know if this helps or else we can discuss further
----------
If answer helps, you can mark it 'Accept Answer'