DOS to execute all SQL scripts in a directory and subdirectories

I need a DOS command or a batch (.bat) file that I can execute to run all the * .sql scripts in the directory and its subdirectories. What will be the solution?

+3
source share
4 answers

Below you will get

for /r %f in (*.sql) do echo %f

Run from the command line, which will print the names of all the SQL files in the current directory and in all subdirectories.

Then replace sqlcmd <connection args> -i%fon echo %fthe scripts.

Hope this helps.

+6
source

. sql . output.txt , . :

  • [YourDatabase] - , .
  • [YourPath] - , .
  • [YourServerName\YourInstanceName] - SQL, '\'
  • "=" , .
  • '='
  • [YourPath]
  • , [YourPath] "\"

    SET = [YourDatabase]

    SET ScriptsPath = [YourPath]

    SET ServerInstance = [YourServerName\YourInstanceName]

    IF EXIST "% ScriptsPath% output.txt" del "% ScriptsPath% output.txt"

    NUL > "% ScriptsPath% output.txt"

    FOR/R "% ScriptsPath%" %% G IN (*.sql) DO (

    sqlcmd -d% % -S% ServerInstance% -i "%% G" -o "%% G.txt"

    ..................................................................................... → "% ScriptsPath% output.txt"

    echo : "%% G" → "% ScriptsPath% output.txt"

    ..................................................................................... → "% ScriptsPath% output.txt"

    copy "% ScriptsPath% output.txt" + "%% G.txt" "% ScriptsPath% output.txt"

    del "%% G.txt"

    )

+3
for %f in ("c:\path\to\dir\*.sql") do sqlcmd -S [SERVER_NAME] -d [DATABASE_NAME] -i "%f" -b
+2

for. , , DOS , , DOS "cmd.exe Windows XP", - :

for /r . %f in (*.sql) do @echo %f

, . , , , SQL, echo.

for /?.

0

Source: https://habr.com/ru/post/1734885/


All Articles