使用游标逐个清空表
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/
博客文章仅供交流学习,请勿用于商业用途。如需转载,请务必注明出处。