欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

sqlServer2005 清空数据库中所有数据,表和表结构和约束都不删

程序员文章站 2024-03-21 08:50:28
...
有两个地方需要改,
第一行和最后一行的testdb改成你的数据库名


use testdb

declare @tablename varchar(max)
declare havetable cursor for select [name] from sysobjects where xtype='U'
open havetable
fetch next from havetable into @tablename
WHILE @@FETCH_STATUS = 0
begin
exec('delete from '+ @tablename)
fetch next from havetable into @tablename
end
close havetable
deallocate havetable
DUMP TRANSACTION testdb WITH NO_LOG


黑色头发:http://heisetoufa.iteye.com/
相关标签: sql