首页 > Linux操作系统 > Linux操作系统 > 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
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/16436858/viewspace-616348/ ,如需转载,请注明出处,否则将追究法律责任。