dbsql interactive command interpreter

You can use the dbsql command to connect to a Db2® database and run queries from a command line interface.

The dbsql command is based on an IBM® Netezza® command called nzsql. The dbsql command has a similar interface for running queries against Db2 environments.

For information about how to obtain the Db2 support tools, which include the dbsql command, see Db2 support tools overview.

When you use the dbsql command on a remote client, you must supply a database user account, the password, the name of the database, and optionally, the schema. In the following sample dbsql command, the connection information is specified on the command line; if you do not specify the user, password, and database, you are prompted for that information. You can run the command from a command window or shell prompt.
dbsql -d bludb -u mark -pw bluepass 
Welcome to dbsql, the IBM dashDB SQL interactive terminal.

Type:  \? for help on internal slash commands
       \g or terminate with semicolon to execute query
       \q to quit 
BLUDB.MARK(MARK)=>

The previous and subsequent examples in this topic apply to the Db2 managed service and to IBM Db2 Warehouse if you did not obtain the Db2 support tools (which include the dbsql command) from the Db2 Warehouse image or client container. If you obtained the Db2 support tools from the Db2 Warehouse image or client container, see Db2 support tools overview for information about how to run the examples.

A sample SQL statement follows to illustrate the components of the dbsql command line.
Sample dbsql query with legend for each part of the prompt and output
Figure legend Description
1 Database name
2 Schema name. If you do not specify a schema, the command uses a default schema that matches the name of the database user.
3 User name
4 Query
5 Query result

You enter the user, database, schema, and password information on the dbsql command line after you begin your dbsql session. The following command shows how to connect to a specific database and schema:

dbsql -d bludb -schema test -u mlee -pw blue
 Welcome to dbsql, the IBM dashDB SQL interactive terminal.

Type:  \? for help on internal slash commands
       \g or terminate with semicolon to execute query
       \q to quit 
 BLUDB.TEST(MLEE)=>
Tip: In many topics, the dbsql command output examples omit the welcome text for brevity.

To exit the dbsql command line interpreter, type \q and press Enter.