Solved

SQl Server - background task to delete records.

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

Assisted Solution

by:Pawan Kumar Khowal
Pawan Kumar Khowal 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 33

Accepted Solution

by:
paulmacd 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
 

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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 33

Expert Comment

by:paulmacd
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

After restoring a Microsoft SQL Server database (.bak) from backup or attaching .mdf file, you may run into "Error '15023' User or role already exists in the current database" when you use the "User Mapping" SQL Management Studio functionality to al…
Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now