现在的位置: 首页 > 综合 > 正文

SQL:清空数据库所有数据

2013年02月07日 ⁄ 综合 ⁄ 共 297字 ⁄ 字号 评论关闭

使用游标逐个清空表
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

 

抱歉!评论已关闭.