Websense DB cleanup | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Websense DB cleanup

I am currently running this T-SQL statement every month to clean up several tables in the DB from the past months. We would like to automate this T-SQL statement to run as a maintenance job every month to leave 3 months worth of data. Any ideas how I would go about this without manually changing the T-SQL statement every month?? Any reply is a good reply at this point. Thanks USE (db name)
delete from incoming where date_time between ‘2006-04-01 00:00:00’ and ‘2006-05-01 00:00:00’
delete from summary_url where date_time between ‘2006-04-01 00:00:00’ and ‘2006-05-01 00:00:00’
delete from summary where date_time between ‘2006-04-01 00:00:00’ and ‘2006-05-01 00:00:00’
delete from trend_browse_time where start_date between ‘2006-04-01 00:00:00’ and ‘2006-05-01 00:00:00’
delete from trend_disposition where start_date between ‘2006-04-01 00:00:00’ and ‘2006-05-01 00:00:00’
delete from trend_protocol where start_date between ‘2006-04-01 00:00:00’ and ‘2006-05-01 00:00:00’
delete from trend_wellness where start_date between ‘2006-04-01 00:00:00’ and ‘2006-05-01 00:00:00’
GO
delete from dbname..incoming where date_time < dateadd (mm, -3 , getdate())
delete from dbname..summary_url where date_time < dateadd (mm, -3 , getdate())
delete from dbname..summary where date_time < dateadd (mm, -3 , getdate())
delete from dbname..trend_browse_time where start_date < dateadd (mm, -3 , getdate())
delete from dbname..trend_disposition where start_date < dateadd (mm, -3 , getdate())
delete from dbname..trend_protocol where start_date < dateadd (mm, -3 , getdate())
delete from dbname..trend_wellness where start_date < dateadd (mm, -3 , getdate())
GO MohammedU.
Moderator
SQL-Server-Performance.com All postings are provided “AS IS” with no warranties for accuracy.

]]>