IMPAX 6.5.1 Server Knowledge Base home > SQL Server home

Running osql to access SQL Server data

The osql utility can be used to access and change data in instances of SQL Server. This command prompt utility can execute one or more SQL statements and can either display the results of a query, or save the results in a text file.

Use the osql utility to enter Transact-SQL statements, system procedures, and script files. The utility uses ODBC to communicate with the server. As of SQL Server 2005, osql replaced the isql utility entirely.

To run osql to access SQL Server data

  1. Open a command prompt and type

    osql -Ulogin_id -Ppassword -Sserver_name

    where

    • login_id is the user login ID. It is case-sensitive.

    • password is a user-specified password. It is case-sensitive. If the -P option is not used, you are prompted for a password.

    • server_name specifies the default instance of SQL Server to connect to or the named instance of SQL Server on that server. If no server is specified, osql connects to the default instance of SQL Server on the local computer. This option is required if you are executing osql from a remote computer.

  2. At the prompt, you can type SQL statements and run them interactively (for example).

    Note:

    Note:

    As you type SQL statements and press Enter, osql caches the statements, but does not run them. To run the cached statements, type go at the start of a new line, then press Enter.

  3. After you have run the last batch of SQL statements, to terminate the utility, type exit or quit at the start of a new line.


For more information about this utility, refer to Command Prompt Utilities on the Microsoft site (http://msdn.microsoft.com/en-us/library/aa246885(v=SQL.80).aspx).


Topic number: 118801

Applies to: IMPAX 6.5.1 Server Knowledge Base