您的位置:首页 > 数据库

SQL:清空数据库所有数据

2009-10-12 15:38 197 查看
使用游标逐个清空表
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: