统一删除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

posted @ 2020-05-09 14:34  滑溜溜的小热浪  阅读(312)  评论(0编辑  收藏  举报