Thursday, 9 February 2012

DOSsing around

Having just finished a command line scripting system, here are the bookmarks/ techniques I used.
I can't share it here, but I'm quite proud of the finished result, which allows me to recursively execute folders of .sql files and update a central table of which patches have been applied.

DOS Commands & Batch files
 
A little DOS for a poor DBA

DOS String Manipulation

DOS FOR command

  
File name parsing in batch file and more idioms

Loop files in a directory with a batch file


Executing a folder of sql scripts

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

for %i in (*.*) do echo %~ni

NB : You need to change "%i" to "%%i" for use inside a batch file.


Adding SQL ...

osql is command line tool from SQL 2000. Replaced by SQLCMD in SQL 2005+ and scheduled for deprecation but is still present.

osql -S{server} -d{database} -U{user} -P{password} -f 65001 -n -i{filename} -b 

See Solace : OSQL & SQLCMD 



No comments: