amir
amir

Reputation: 1

Delete a list of files from SQL Server table

I have a SQL Server table with a list of file paths for files 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.

Upvotes: 0

Views: 423

Answers (2)

dcp
dcp

Reputation: 55464

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.

Upvotes: 2

Anders Zommarin
Anders Zommarin

Reputation: 7274

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

Upvotes: 0

Related Questions