Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Schedule SQL Server 7 to dump old records?

Status
Not open for further replies.

rodbac

Programmer
Jun 21, 2001
23
US
Is there a way to schedule SS7 to automatically purge records from a specific database that are older than a certain date? I have a db set up that is going to grow fairly quickly and I would like to set it up so that old records will get deleted and the db will not grow infinitely. Thanks for any help!
 
Create a scheduled job to either run a T-SQL statement or stored procedure to delete the records.

The T-SQL code would be something like the following.

Delete table1 Where thedate<convert(char(11),dateadd(day,-30,getdate()))

This would delete records more than 30 days older than current server date. Terry
------------------------------------
Experience is the hardest kind of teacher. It gives you the test first, and the lesson afterward.
 
create a store procedure that looks something like this

delete from mytable
where mydate <= datediff(day,-30,getdate())

replace the -30 with the appropriate number of days.

Use sql server agent and schedule this as a job to run every night or however often you want

All of this assumes that you have a field in the database that has the appropriate date in it. If not, create one.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top