Q
Problem solve Get help with specific problems with your technologies, process and projects.

Delete .bak files automatically with CLR

I have a query and I want to know if there is a stored procedure, SQL script, or T-SQL script to delete the .bak files, which are older than seven days. I have set up daily backups and after the day seven, the .bak files should purge off. How can I get these .bak files to delete?

I have a query and I want to know if there is a stored procedure, SQL script, or T-SQL script to delete the .bak files, which are older than seven days. I have set up daily backups and after the day seven, the .bak files should purge off. How can I get these .bak files to delete?
Ideally you should use a database maintenance plan to handle this. The functionality is built in and handled by maintenance plans in both SQL Server 2000 and 2005. I just don't think Transact-SQL is the right tool for deleting old backup files. Before SQL Server 2005 I did use xp_cmdshell to execute OS commands. While these extended stored procedures still exist, they'll eventually go away because of what CLR integration provides.

Since you are running SQL Server 2005 you are able to create stored procedures in C# or VB.Net using Visual Studio...

2005. That is exactly the route I would recommend. If you do, you will be able to execute the CLR procedure just like you would execute a Transact-SQL created stored procedure.

This was last published in February 2007

Dig Deeper on SQL Server Stored Procedures

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchBusinessAnalytics

SearchDataCenter

SearchDataManagement

SearchAWS

SearchOracle

SearchContentManagement

SearchWindowsServer

Close