Forum Moderators: open

Message Too Old, No Replies

Automatic Delete

         

webboy1

10:35 am on Dec 13, 2002 (gmt 0)

10+ Year Member



Hi,

Can anyone tell me how to setup an automatic delete in my MSSQL Database. I would like to set something up so that all entries from 2 months previous will be deleted. i.e. When January comes, everything from November will be deleted, when February comes, everything from December will be deleted. I know i can set up a delete admin page, but is there anyway to get SQL Server to automatically do it?

Regards
Webboy

jpjones

11:48 am on Dec 13, 2002 (gmt 0)

10+ Year Member



Hello,
I'm not overly profficient with MSSQL, but this is the way I tackle this to maintain several other databases automatically:

1) Create an SQL function in a script page which deletes the records you want.

2) Call this script every month through an automatic scheduler, such as the NT at command, or a crontab/lynx combination.

It's not the answer you were looking for, but I hope it helps!

JP

webboy1

12:32 pm on Dec 13, 2002 (gmt 0)

10+ Year Member



Cheers jpjones,

An answer is an answer! It's more than i had thought of. I will give it a try.

Regards
webboy

tomasz

3:16 pm on Dec 13, 2002 (gmt 0)

10+ Year Member



the best way is to create SQL job in Enterprise Manager and schedule it to run daily at certain time.
Your job SQL

Delete from myTable
where DATEDIFF(m, mydatefield, GETDATE()) >= 2