Solved

SQl Server - background task to delete records.

Posted on 2016-10-28
8
54 Views
Last Modified: 2016-10-28
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
Comment
Question by:HLRosenberger
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 29

Assisted Solution

by:Pawan Kumar
Pawan Kumar earned 125 total points
ID: 41864192
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
 
LVL 34

Accepted Solution

by:
Paul MacDonald earned 250 total points
ID: 41864205
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
 
LVL 1

Author Comment

by:HLRosenberger
ID: 41864269
it's not a one time thing.  I want it to  be done daily.
0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
LVL 1

Assisted Solution

by:Jeff Edmunds
Jeff Edmunds earned 125 total points
ID: 41864287
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
 
LVL 34

Expert Comment

by:Paul MacDonald
ID: 41864372
"I want it to  be done daily."
That's not a problem.
0
 
LVL 1

Author Comment

by:HLRosenberger
ID: 41864556
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
 
LVL 1

Author Comment

by:HLRosenberger
ID: 41864586
ah, I got the job working.   Now just to schedule it to run every day.
0
 
LVL 1

Author Closing Comment

by:HLRosenberger
ID: 41864587
Thanks to all!
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question