开发者

Delete a list of files from SQL Server table

开发者 https://www.devze.com 2023-02-13 04:50 出处:网络
I have a SQL Server table with a list of file paths for fi开发者_高级运维les that I need to delete from my windows system, is there any way I can accomplish this using batch file in command prompt or

I have a SQL Server table with a list of file paths for fi开发者_高级运维les that I need to delete from my windows system, is there any way I can accomplish this using batch file in command prompt or any software to help me do this?? appreciate any help.


You could write a select statement that will create the commands for you, then run it from the command line:

e.g.

SELECT 'del /Q ' + file_name FROM your_table;

Save the output results to a file, then you can run it from the command line.


And you may automate the whole thing a little bit more by doing it on the command line with sqlcmd:

sqlcmd -d MyDb -Q "SELECT * FROM (SELECT 'DELETE /Q ' + file_name AS x FROM your_table UNION ALL SELECT 'EXIT') AS x" -h -1 -o temp.bat
temp.bat
DEL temp.bat
0

精彩评论

暂无评论...
验证码 换一张
取 消