/*
--下面的调下将清空数据库
exec TruncateDatabase 'truncate %tablename%'
*/
alter proc dbo.TruncateDatabase
@SqlExecute varchar(3000)='Select * from %tablename%'
as
begin
declare @tablename varchar(100)
,@sql varchar(3000)
--定义游标
declare mycur cursor for
select name from dbo.sysobjects where xtype='u'
--打开
open mycur
fetch next from mycur into @tablename
while @@fetch_status=0
begin
set @sql=Replace(@sqlExecute,'%tablename%',@tablename)
--执行操作
print @sql
Execute(@sql)
--到下一个表
fetch next from mycur into @tablename
end
close mycur
deallocate mycur
end
go