Empty All tables content in SQL Server

DECLARE @tableCatalog VARCHAR (1024) ,

@tableSchema VARCHAR (1024), @tableName VARCHAR (1024), @tableType VARCHAR (1024)
DECLARE cursorTemp CURSOR FOR
SELECT * FROM INFORMATION_SCHEMA.TABLES
OPEN cursorTemp
FETCH cursorTemp INTO @tableCatalog, @tableSchema, @tableName, @tableType


-- start the main processing loop.
WHILE @@Fetch_Status = 0
BEGIN
    EXEC (' ALTER TABLE '+@tableName+' NOCHECK CONSTRAINT ALL;' +
    ' DELETE FROM '+ @tableName +';'+
    ' ALTER TABLE '+@tableName+' CHECK CONSTRAINT ALL ')
    FETCH cursorTemp INTO @tableCatalog, @tableSchema, @tableName, @tableType
END

CLOSE cursorTemp
DEALLOCATE cursorTemp

Leave a Reply

Your email address will not be published. Required fields are marked *