• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
敬YES
Now Or Never
博客园    首页       联系   管理    订阅  订阅
SQL:清空数据库所有数据

使用游标逐个清空表
declare tempCursor cursor for
select name from sysobjects where type='U'--获取数据库中所有表名:‘U’表示用户表

open tempCursor
declare @tbName varchar(50)

fetch next from tempCursor
into @tbName

while @@fetch_status=0
begin
 exec('truncate table '+ @tbName )

fetch next from tempCursor
into @tbName
end

close tempCursor
deallocate tempCursor
go


 

作者:陈敬(公众号:敬YES)
出处:http://www.cnblogs.com/janes/
博客文章仅供交流学习,请勿用于商业用途。如需转载,请务必注明出处。

posted on 2009-10-12 15:38  敬YES  阅读(2169)  评论(3)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3