For SQL Server 6.5 information, see ISQLPASSWORD in What's New for SQL Server 6.5.
Allows you to enter SQL statements and system procedures.
isql /U login_id [/e] [/E] [/p] [/n] [/d dbname] [/q "query"] [/Q "query"]
[/c cmdend] [/h headers] [/w columnwidth] [/s colseparator]
[/t timeout] [/m errorlevel] [/L] [/?] [/r {0 | 1}]
[/H wksta_name] [/P password]
[/S servername] [/i inputfile] [/o outputfile] [/a packet_size]
where
SET table = sysobjects
isql /q "Select * from %table%"
Use double quotation marks around the query and single quotation marks around anything embedded in the query.
The isql utility is started directly from the operating system with the case-sensitive options listed here. Once started, isql accepts SQL commands and sends them to SQL Server interactively. The results are formatted and printed on the standard output device (the screen). Use QUIT or EXIT to exit from isql.
If you do not specify a username when you start isql, SQL Server checks for the environment variables ¾ for example, isqluser=(user) or isqlserver=(server), and uses those. If no environment variables are set, the workstation username is used. If you do not specify a server, the name of the workstation is used.
If neither the /U or /P options are used, SQL Server uses the currently logged in user account and will not prompt for a password. This is useful when using integrated or mixed security. For details about security, see the Microsoft SQL Server Administrator's Companion.
In addition to using Transact-SQL statements within isql, use the following commands:
Command | Description |
---|---|
GO | Executes a command. |
RESET | Clears any statements you have entered. |
ED | Calls the editor. |
!! command | Executes an operating-system command. |
QUIT or EXIT( ) | Exits from isql. |
ctrl+c | Terminates a query without exiting from isql. |
The command terminators, GO (by default), RESET, ED, !!, EXIT, QUIT, and CTRL+C, are recognized only if they appear at the beginning of a line, immediately following the isql prompt. Anything entered on the same line after these keywords is disregarded by isql.
Terminate a command by typing a line beginning with a command terminator. You can follow the command terminator with an integer to specify how many times the command should be run. For example, to execute this command 100 times, type:
SELECT x = 1 go 100
The results are printed once, at the end of execution.
With isql, there is a limit of 1000 characters per line. Large statements should be spread across multiple lines.
The user can call an editor on the current query buffer by typing ED as the first word on a line. Operating-system commands can also be executed by starting a line with two exclamation points (!!) followed by the command. The editor is defined in the EDITOR environment variable. The default editor is "edit" for MS-DOS and Windows NT. You can specify a different editor by setting the EDITOR environment variable. For example, to make the default editor Notepad, at the operating-system prompt, type:
SET EDITOR=notepad
The command recall facilities of DOSKEY can be used to recall and modify previously entered isql statements on a Windows NT - based computer. The existing query buffer can be cleared by typing RESET on a line by itself. It causes any pending input to be discarded.
When running stored procedures, isql prints a blank line between each set of results in a batch. In addition, the "0 rows affected" message does not appear when it doesn't apply to the statement executed.
To use isql interactively, type the isql command (and any of the options) at the operating-system prompt.
You can read in a file containing a query (such as STORES.QRY) for execution by isql by typing a command similar to this:
isql /U alma /P /i stores.qry
The file must include a command terminator(s). The results are displayed on the user's workstation.
You can read in a file containing a query (such as TITLES.QRY) and direct the results to another file by typing a command similar to this:
isql /U alma /P /i titles.qry /o titles.res
When using isql interactively, you can read an operating-system file into the command buffer with :r filename. Do not include a command terminator in the file; enter the terminator interactively once you have finished editing.
You can include comments in a Transact-SQL statement submitted to SQL Server by isql. Two types of commenting styles are allowed. For more information, see the Comments topic.
For example:
SELECT au_lname, au_fname -- Retrieve authors' last and first names. FROM authors a, titles t, titleauthor ta WHERE a.au_id = ta.au_id AND t.title_id = ta.title_id /* This is a three-way join that links authors ** to the books they have written. */
Note Do not include a GO command within a comment. A GO command within a comment produces an error message.
You can return the result of an integer SELECT as the return value from isql. The first column of the first result row is converted to a 4-byte integer (long). MS-DOS passes the low byte to the parent process or operating-system error level. Windows NT passes the entire 4-byte integer. The syntax is:
EXIT(query)
For example:
EXIT(SELECT @@rowcount) EXIT(SELECT 5)
You can also include the exit parameter as part of a batch file. For example:
isql /Q "EXIT(SELECT COUNT(*) FROM '%1')"
The isql utility passes everything between the parentheses ( ) to the server exactly as entered. The EXIT( ) statement can span lines. If a stored system procedure selects a set and returns a value, only the selection is returned. The EXIT( ) statement with nothing between the parentheses executes everything preceding it in the batch and then exits with no return value.
There are four exit formats:
Does not execute the batch; quits immediately and returns no value.
Executes the batch, and then quits and returns no value.
Executes the batch, including the query, and then quits, returning the results of the query.
RAISERROR(50001, 10, 127)
This error will cause the isql script to terminate and the message ID 50001 will be returned to the to the client.
The return values - 1 to - 99 are reserved by SQL Server; isql defines the following values:
- 100: Error encountered prior to selecting return value.
- 101: No rows found when selecting return value.
- 102: Conversion error when selecting return value.