删除数据库的所有表数据:
declare @trun_name varchar(50)
declare name_cursor cursor for
select 'truncate table ' + name from sysobjects where xtype='U' and status > 0
open name_cursor
fetch next from name_cursor into @trun_name
while @@FETCH_STATUS = 0
begin
exec (@trun_name)
print @trun_name
fetch next from name_cursor into @trun_name
end
close name_cursor
deallocate name_cursor
本文提供了一段SQL Server过程示例代码,该过程通过游标遍历数据库中所有的表,并执行截断操作来清空每个表的数据。适用于需要批量清空数据库中所有表数据的场景。
6361

被折叠的 条评论
为什么被折叠?



