Friday, 25 October 2019

Connect to SQL Server with .bat file to run .SQL commands.

Save the following commands in a notepad with .bat as extension-

SQL Auth Mode:

REM name of the server that hosts the SQL Server DB
set svr= localhost
REM name of the DB
set dbname=databaseNAME
REM credentials of the user that has permissions to create DB objects
set uname=USERname
set pwd=PASSword

osql -S %svr% -d %dbname% -U %uname% -P %pwd% -i "Create_Table"  -o "Create_Table.txt"  -n


Windows Auth Mode:

REM name of the server that hosts the SQL Server DB
set svr= localhost
REM name of the DB
set dbname=databaseNAME

osql -E -S %svr% -d %dbname% -i "Create_Table.sql"  -o "Create_Table.txt"  -n


No comments:

Post a Comment