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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automatic table deletion

Status
Not open for further replies.
Joined
Dec 11, 2000
Messages
281
Location
GB
Help me, I'm drowning!

I have a table (ZZ_TRANS_LOG) in our database that needs to have its contents deleted on a regular basis to prevent it from growing too large.
Is there a way to automate this process (through Transact_SQL or whatever)?
Alternatively, it possible to cap a table size so that the oldest data gets removed when the table reaches capacity?
Please give answers suitable for a fellow with very limited sql experience who has just had a sql system dumped on him!!

Cheers

Steve
 
You could write a stored procedure, which contains some SQL like the following:

Delete from ZZ_TRANS_LOG
where ZZ_TRANS_LOG.Date_entered_column < (select getdate () - 30)

This will delete all records, which were entered more then 30 days before the current date. This is assuming you have a column something like date entered on you table.

You can then set up a scheduled job to run the stored procedure as and when required.

Rick.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top