日期:2014-05-16  浏览次数:20631 次

sqlServer2005 清空数据库中所有数据,表和表结构和约束都不删
有两个地方需要改,
第一行和最后一行的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/