Solved

SQl Server - background task to delete records.

Posted on 2016-10-28
8
36 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 28

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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Webservices in T-SQL 3 35
Need help how to find where my error is in UFD 6 40
MS SQL BCP Extra Lines Between Records 2 25
How can I get the entire database script? 7 15
SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

820 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