Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQl Server - background task to delete records.

Posted on 2016-10-28
8
Medium Priority
?
69 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
8 Comments
 
LVL 35

Assisted Solution

by:Pawan Kumar
Pawan Kumar earned 500 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 1000 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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
LVL 1

Assisted Solution

by:Jeff Edmunds
Jeff Edmunds earned 500 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

876 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