• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 92
  • Last Modified:

SQl Server - background task to delete records.

Is there a way to create some Task in SQL server that deletes records from a table based on a date column in said table?
0
HLRosenberger
Asked:
HLRosenberger
3 Solutions
 
Pawan KumarDatabase ExpertCommented:
You can create a SQL job and inside that you can do that with your DELETE command.  Yes you can use a date in there.

Or if it is a one time activity , create a script and inside that delete the required rows.
0
 
Paul MacDonaldDirector, Information SystemsCommented:
Yes.  
In SSMS, go to SQL Server Agent -> Jobs, right-click and select "New Job..." and fill out the relevant fields.  Your SQL will go under "Steps" and you can schedule the job to run when you want under "Schedules".
0
 
HLRosenbergerAuthor Commented:
it's not a one time thing.  I want it to  be done daily.
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
Jeff EdmundsApplication Developer/SQL DBACommented:
You can combine what the last two folks said to do... Your SQL Agent Job can be scheduled to run daily and the job itself can be to execute the script which deletes the records. When you create the SQL job, add a new Step, and select Transact SQL Script as the Type. In the Command box, just type in the SQL script to use. Then under Schedules you can set the job to run daily at whatever time you wish.
0
 
Paul MacDonaldDirector, Information SystemsCommented:
"I want it to  be done daily."
That's not a problem.
0
 
HLRosenbergerAuthor Commented:
paulmacd - Do I have to add a step to the job?  Does the job call a stored proc that has my SQL Delete?  Or can I define the SQL delete right in the main job?
0
 
HLRosenbergerAuthor Commented:
ah, I got the job working.   Now just to schedule it to run every day.
0
 
HLRosenbergerAuthor Commented:
Thanks to all!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now