问题
I am trying to use TSQL to delete a .txt file at the end of a process. My restriction is that I cannot use xp_cmdshell. I had tried using the undocumented xp_delete_file but from what I can find it will only delete SQLServer native .ldf or .bak files. Is there another approach that can be used? I am running in SQL server 2008 R2.
回答1:
Use SQL Server Agent CmdExec job step? This can run "del"...
http://msdn.microsoft.com/en-us/library/ms190264.aspx
In step 8 you'd have del c:\importpath\toasted.txt
Your comment to your question states you are running a "SQL job", so no need to overkill with CLR or sp_OA% solutions :-)
来源:https://stackoverflow.com/questions/4830464/how-do-i-delete-a-txt-file-with-tsql-without-using-xp-cmdshell