Delete .bak files automatically with CLR |
 |
EXPERT RESPONSE FROM: Joe Toscano

|
 |
|


|
| > |
QUESTION POSED ON: 16 February 2007
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?
|
|
|
To continue reading for free, register below or login
To read more you must become a member of SearchSQLServer.com
');
// -->

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.
|
|
|

|
|
 |

 |
 |
Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and
answer pairs from more than 250 TechTarget industry experts.
|
 |
 |
 |
|
 |
 |
 |
|
 |
|
 |