I am interested in using some kind of a command-line utility for SQL Server similar to Oracle's SQL*Plus. SQL Server seems to have several options: osql, isql, and sqlcmd. However, I am not quite certain which one to use.
Do they all essentially do the same thing? Are there any situations where it is preferable to use one over the others?
Command line utility osql has a main function of providing an interface for the ODBC based query to the SQL server. Osql also allows users to submit a job performed. Isql is a utility whose main function is to allow for Transact-SQL statements.
OSQL is a command line tool that allows you to issue commands to Microsoft SQL Server. To run OSQL, simply bring up a DOS box and type OSQL followed by any required switches.
The osql utility allows you to enter Transact-SQL statements, system procedures, and script files. This utility uses ODBC to communicate with the server. Important. This feature will be removed in a future version of SQL Server.
Running Transact-SQL script files using sqlcmd You can use sqlcmd to execute database script files. Script files are text files that contain a mix of Transact-SQL statements, sqlcmd commands, and scripting variables. For more information about how to script variables, see Use sqlcmd with Scripting Variables.
Use sqlcmd-- it's the most fully featured product.
EDIT: Times have changed since I replied on this a couple of years ago. Nowadays, you can also use the invoke-sqlcmd cmdlet in PowerShell. If you're used to PowerShell or plan to do any scripting of any sophistication, use this instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With