SQL 遍历删除所有表的数据

https://www.cnblogs.com/yige/p/5193253.html

declare @sqlTabName varchar(100);
-- 声明游标
DECLARE C_Employees CURSOR FAST_FORWARD FOR
   SELECT name FROM sysobjects WHERE  type='U' ORDER BY name
OPEN C_Employees;

-- 取第一条记录
FETCH NEXT FROM C_Employees INTO @sqlTabName
WHILE @@FETCH_STATUS=0
BEGIN
        
  EXEC('delete  '+@sqlTabName)
   print @sqlTabName;
    -- 取下一条记录
    FETCH NEXT FROM C_Employees INTO @sqlTabName
END

-- 关闭游标
CLOSE C_Employees;

-- 释放游标
DEALLOCATE C_Employees;

posted @ 2019-06-28 15:45  LuoCore  阅读(469)  评论(0编辑  收藏  举报