SQL 删除各表中全部记录
发布时间
阅读量:
阅读量
SQL 清除数据库中所有表的数据(保留结构)
使用游标和truncate语句:
declare c cursor for
select NAME from sysobjects where xtype='U'
declare @t varchar(200)
open c
fetch next from c into @t
while @@FETCH_STATUS=0
begin
exec('truncate table '+@t)
fetch next from c into @t
end
close c
注释:可以通过修改来实现exec执行语句。需要注意的是,在使用数据库操作时应避免使用drop命令。因为 drop命令会彻底删除所有表及其关联结构。
全部评论 (0)
还没有任何评论哟~
