SQL Server help Please

Soldato
Joined
18 Oct 2002
Posts
4,921
Not sure on the naming but for some reason I think its called a Cron Job or somthing similar.

What i've got is a table that contains sessionKeys that have a 2 hour expire time on them. I'm after somthing that I can set to run say every 4 hours that will run through the table and remove all the sessionKeys that have expired.

any ideas ?
 
Just setup a sceduled task that deletes from the table using datediff in the where clause, if the table is large use a table variable of something to loop around to prevent locking for any *** period of time.
 
therubble said:
Just setup a sceduled task that deletes from the table using datediff in the where clause, if the table is large use a table variable of something to loop around to prevent locking for any *** period of time.


and how do I setup these scheduled tasks from what I can find out I think you mean setting up a scheduled task in windows to do it ?

if so this is not an option i dont have access to the windows machine running sql server. , any way I can set something up in enterprise manager ?
 
Last edited:
I don't think you can run a sceduled task in SQL Server directly. How often is the table updated? you could just stick it in a on_update trigger. store the last time the script was run in another table and IF the last run was more than 4 hours (or whatever) ago run the clean up script.

HT
 
umm the On_Update sounds the way to go, will have a look into this and see what I can find.

failing that I can just mention about the schedule task as its a uni assignment.



thanks again mate
 
SQL server has a mechanism inside of it for this very task. Look under management > Sql Server Agent > Jobs

Setup a new Job that executes your SQL on the schedule that it set's dont go the trigger route.
 
therubble said:
SQL server has a mechanism inside of it for this very task. Look under management > Sql Server Agent > Jobs

Setup a new Job that executes your SQL on the schedule that it set's dont go the trigger route.

Can't find that here on studio Menagement Studio, under management theres only SQL Server Logs, Legacy and activity monitor. non of them let me add a server agent.

Will check enterprise manager in a bit as i'm going into uni today.
 
Your not using SQL Server Express by any chance are you? Cause it's not there if thats the case, you would have to use the command line options to do from there.
 
Back
Top Bottom