Advertisement
Guest User

Untitled

a guest
Aug 5th, 2016
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. @ECHO OFF
  2.  
  3. ECHO ***********************
  4. ECHO Remember Batch sCripts?
  5. ECHO Good ol days... but, right now, we got work to do ;-)
  6. ECHO ***********************
  7. ECHO SCRIPT: run_all_sql_in_dir.bat
  8. ECHO SYNTAX: run_all_sql_in_dir [DIR] [HOST] [SERVER] [DBNAME] [USER] [PASSWORD]
  9. ECHO Purpose: should be obvious by now... checks the DIR, and using the connection params, executes all SQL scripts found in that dir, against the specified DB
  10. ECHO Uses some convinient defaults... check the source-code of this script!
  11. ECHO ++++++++++++++++++++++++++++++++++++++++++++++
  12. ECHO Rock-N-Roll time... tnx to NX@2016...
  13. ECHO **********************************************
  14.  
  15. REM by default, we use the current working directory as the path where the SQL scripts are searched for
  16. SET ROOT_DIR=%CD%
  17. SET HOST=localhost
  18. SET SERVERNAME=MACHINE\INSTANCE_NAME
  19. SET DBNAME=THE_GLORIOUS_DB
  20. SET USER=DBA
  21. SET PASSWORD=Kr@ZYPASS?
  22.  
  23. REM if params were passed, use those...
  24. IF defined %1 SET ROOT_DIR=%1
  25. IF defined %1 SET HOST=%2
  26. IF defined %2 SET SERVERNAME=%3
  27. IF defined %1 SET DBNAME=%4
  28. IF defined %2 SET USER=%5
  29. IF defined %2 SET PASSWORD=%6
  30.  
  31. ECHO Processing all SQL scripts under the path: %ROOT_DIR%
  32. ECHO Using the SERVER/DB : %SERVERNAME%/%DBNAME%
  33.  
  34. REM okay, we obtain the entire list of sql scripts (*.sql) in current dir
  35. REM and execute them against the specified server and db..
  36.  
  37. ECHO Running the scripts...
  38. FOR /R "%ROOT_DIR%" %%F in (*.sql) do (
  39. echo "Processing SCRIPT: %%F"
  40. sqlcmd -S %SERVERNAME% -d %DBNAME% -U %USER% -P %PASSWORD% -H %HOST% -i "%%F"
  41. )
  42.  
  43. ECHO JOB COMPLETED.
  44. ECHO Perhaps, you can now go let laid... hehehe.
  45. PAUSE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement