SQL Server tip – Calling .SQL scripts from osql

This is quite simple and handy; You can call it with some parameters.

Display osql parameters:

C:\> osql /?
usage: osql              [-U login id]          [-P password]
[-S server]            [-H hostname]          [-E trusted connection]
[-d use database name] [-l login timeout]     [-t query timeout]
[-h headers]           [-s colseparator]      [-w columnwidth]
[-a packetsize]        [-e echo input]        [-I Enable Quoted Identifiers]
[-L list servers]      [-c cmdend]            [-D ODBC DSN name]
[-q "cmdline query"]   [-Q "cmdline query" and exit]
[-n remove numbering]  [-m errorlevel]
[-r msgs to stderr]    [-V severitylevel]
[-i inputfile]         [-o outputfile]
[-p print statistics]  [-b On error batch abort]
[-X[1] disable commands [and exit with warning]]
[-O use Old ISQL behavior disables the following]
<EOF> batch processing
Auto console width scaling
Wide messages
default errorlevel is -1 vs 1
[-? show syntax summary]

Call external script located on C: of the server with trusted connection:

osql -E -d Database -n-1 -i C:\Script.sql -o C:\log.txt

About Bruno Carvalho

Coffee addicted tech guy.
This entry was posted in SQL Server and tagged , , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s