select name into #temp
from sysobjects
where xtype='U'
go
declare @table_name nvarchar(255)
declare @sql nvarchar(2000)
while (select top 1 name from #temp) is not null
begin
set @table_name=(select top 1 name from #temp)
set @sql='delete from ['+@table_name+']'
exec(@sql)
delete from #temp
where name=@table_name
end
--主外键约束
select name constraint_name
from sysobjects
where xtype in ('PK','f')
如果要清理的数据是一段时间之前的,可以根据log文件,来恢复。
其他的情况也只能是delete 和 drop了
如果带有主外键约束,可以写个存储过来,来统一执行