Friday, December 12, 2008

TSQL Clearing CRASH tables

declare @strtablename varchar(250)
declare @strsql varchar(250)
declare tcur cursor for
select name from sys.objects where name like 'crash%'
and type ='u'
open tcur
fetch tcur into @strtablename
while @@fetch_status = 0
begin
set @strsql = 'delete from dbo.'+ @strtablename + ' where crash_date <= getdate() - 60 '
exec( @strsql)
fetch next from tcur into @strtablename
end
close tcur
deallocate tcur

Welcome to TSQL 101

One of the many 101 blogs I reserverd