Ever wanted to delete files from the local machine that your SQL Server database is running?
You can do it using the extended stored procedure xp_cmdshell like this:
EXEC master..xp_cmdshell 'del C:\file.txt'
But this requires the sysadmin option on the SQL Server and Admin role from
NT server. In most instances it is not preferable to give these privileges. So to delete files without requiring this access use the built-in SQL Server
Automation APIs and the FileSystemObject:
DECLARE @hr int
DECLARE @ole_FileSystem int
EXEC @hr = sp_OACreate 'Scripting.FileSystemObject',
EXEC @hr = sp_OAMethod @ole_FileSystem, 'DeleteFile',
EXEC @hr = sp_OADestroy @ole_FileSystem