统一删除SQL Server某一个数据库内批量表数据
DECLARE deleteDBTableData
CURSOR FOR (SELECT name FROM sysobjects WHERE xtype='U' AND (name LIKE 'XXXX%' OR name LIKE 'YYY%'))
OPEN deleteDBTableData
DECLARE @SQL NVARCHAR(360)
DECLARE @Name NVARCHAR(36)
FETCH NEXT FROM deleteDBTableData INTO @Name
WHILE @@FETCH_STATUS=0
BEGIN
SET @SQL='DELETE FROM '+ @Name
BEGIN TRY
EXECUTE(@SQL)
END TRY
BEGIN CATCH
END CATCH
FETCH NEXT FROM deleteDBTableData INTO @Name
END
CLOSE deleteDBTableData
DEALLOCATE deleteDBTableData
GO