环境:
DB2 V9.1
Windows XP Professional CN
准备工作:
进入DB2命令行控制处理器,输入db2
C:\DB291\IBM\SQLLIB\BIN>db2
(c) Copyright IBM Corporation 1993,2003
DB2 ADCL 9.1.0 的命令行处理器
可从命令提示符处发出数据库管理器命令和 SQL 语句。例如:
db2 => connect to sample
db2 => bind sample.bnd
要获得一般帮助,输入:?。
要获得命令帮助,输入:? command,其中 command 可以是
数据库管理器命令的前几个关键字。例如:
? CATALOG DATABASE 用于关于 CATALOG DATABASE 命令的帮助
? CATALOG 用于关于所有 CATALOG 命令的帮助。
要退出 db2 交互方式,在命令提示符处输入
QUIT。在非交互方式下,所有命令都必须以“db2”作前缀。
要列出当前命令选项设置,输入 LIST COMMAND OPTIONS。
要获取更详细的帮助,请参阅 Online Reference Manual。
db2 =>
查看命令:
一、查看所有命令:
db2 => ?
ACTIVATE DATABASE GET CONTACTS RECOVER
ADD CONTACT GET/UPDATE DB CFG REDISTRIBUTE DB PARTITION
ADD CONTACTGROUP GET/UPDATE DBM CFG REFRESH LDAP
ADD DATALINKS MANAGER GET DBM MONITOR SWITCHES REGISTER LDAP
ADD DBPARTITIONNUM GET DESCRIPTION FOR HEALTH REGISTER XMLSCHEMA
ADD XMLSCHEMA GET NOTIFICATION LIST REGISTER XSROBJECT
ARCHIVE LOG GET HEALTH SNAPSHOT REORG INDEXES/TABLE
ATTACH GET INSTANCE REORGCHK
AUTOCONFIGURE GET MONITOR SWITCHES RESET ADMIN CFG
BACKUP DATABASE GET RECOMMENDATIONS RESET ALERT CFG
BIND GET ROUTINE RESET DB CFG
CATALOG APPC NODE GET SNAPSHOT RESET DBM CFG
CATALOG APPN NODE HELP RESET MONITOR
CATALOG DATABASE HISTORY RESTART DATABASE
CATALOG DCS DATABASE IMPORT RESTORE DATABASE
CATALOG LDAP DATABASE INITIALIZE TAPE REWIND TAPE
CATALOG LDAP NODE INSPECT ROLLFORWARD DATABASE
CATALOG LOCAL NODE LIST ACTIVE DATABASES RUNCMD
CATALOG NPIPE NODE LIST APPLICATIONS RUNSTATS
CATALOG NETBIOS NODE LIST COMMAND OPTIONS SET CLIENT
CATALOG ODBC DATA SOURCE LIST DATABASE DIRECTORY SET RUNTIME DEGREE
CATALOG TCPIP NODE LIST DB PARTITION GROUPS SET TABLESPACE CONTAINERS
CHANGE DATABASE COMMENT LIST DATALINKS MANAGERS SET TAPE POSITION
CHANGE ISOLATION LEVEL LIST DBPARTITIONNUMS SET UTIL_IMPACT_PRIORITY
COMPLETE XMLSCHEMA LIST DCS APPLICATIONS SET WRITE
CREATE DATABASE LIST DCS DIRECTORY START DATABASE MANAGER
CREATE TOOLS CATALOG LIST DRDA INDOUBT START HADR
DEACTIVATE DATABASE LIST HISTORY STOP DATABASE MANAGER
DECOMPOSE XML DOCUMENT LIST INDOUBT TRANSACTIONS STOP HADR
DEREGISTER LIST NODE DIRECTORY TAKEOVER
DESCRIBE LIST ODBC DATA SOURCES TERMINATE
DETACH LIST PACKAGES/TABLES UNCATALOG DATABASE
DROP CONTACT LIST TABLESPACE CONTAINERS UNCATALOG DCS DATABASE
DROP CONTACTGROUP LIST TABLESPACES UNCATALOG LDAP DATABASE
DROP DATABASE LIST UTILITIES UNCATALOG LDAP NODE
DROP DATALINKS MANAGER LOAD UNCATALOG NODE
DROP DBPARTITIONNUM LOAD QUERY UNCATALOG ODBC DATA
DROP TOOLS CATALOG MIGRATE DATABASE UNQUIESCE DATABASE
ECHO PING UNQUIESCE INSTANCE
EDIT PREP/PRECOMPILE UPDATE ALERT CFG
EXPORT PRUNE HISTORY/LOGFILE UPDATE COMMAND OPTIONS
FORCE APPLICATION PUT ROUTINE UPDATE CONTACT
GET/UPDATE ADMIN CFG QUERY CLIENT UPDATE CONTACTGROUP
GET ALERT CFG QUIESCE DATABASE UPDATE NOTIFICATION LIST
GET AUTHORIZATIONS QUIESCE INSTANCE UPDATE HISTORY
GET/UPDATE CLI CFG QUIESCE TABLESPACES UPDATE LDAP NODE
GET CONNECTION STATE QUIT UPDATE MONITOR SWITCHES
GET CONTACTGROUP REBIND XQUERY
GET CONTACTGROUPS RECONCILE
注意:某些命令是特定于操作系统,可能不可用。
要获得进一步帮助:
? db2-command - 关于指定命令的帮助
? OPTIONS - 关于所有命令选项的帮助
? HELP - 关于阅读帮助屏幕的帮助
前面的三个选项可以在操作系统提示符下作为 db2 <option> 运行。
!db2ic - DB2 信息中心(仅用于 Windows)
此命令还可以从操作系统提示符处作为 db2ic 运行。
二、查看某一命令的用法
? db2-command - 关于指定命令的帮助
db2 => ? connect
CONNECT [USER username [{USING password
[NEW new-password CONFIRM confirm-password] |
CHANGE PASSWORD}]]
CONNECT RESET
CONNECT TO database-alias
[IN {SHARE MODE | EXCLUSIVE MODE [ON SINGLE DBPARTITIONNUM]}]
[USER username [{USING password
[NEW new-password CONFIRM confirm-password] |
CHANGE PASSWORD}]]
db2 => ? EXPORT
EXPORT TO filename OF {IXF | DEL | WSF}
[LOBS TO lob-path [ {,lob-path} ... ] ][LOBFILE lob-file [ {,lob-file} ... ] ]
[XML TO xml-path [ {,xml-path} ... ] ][XMLFILE filename [ {,filename} ... ] ]
[MODIFIED BY {filetype-mod ...}][XMLSAVESCHEMA]
[METHOD N ( column-name [ {,column-name} ... ] )] [MESSAGES message-file]
{select-statement | XQUERY xquery-statement |
HIERARCHY {STARTING sub-table-name |
(sub-table-name [{, sub-table-name} ...])} [WHERE ...] }
filetype-mod:
NODOUBLEDEL、LOBSINFILE、CHARDELx、COLDELx、DLDELx、DECPLUSBLANK、
DECPTx、DATESISO、1、2、3、4、CODEPAGE=x、STRIPLZEROS 和 NOCHARDEL
db2 => ? ADD CONTACT
ADD CONTACT contact-name TYPE {EMAIL | PAGE [MAXIMUM PAGE LENGTH page-length]}
ADDRESS recipients-address [DESCRIPTION contact-description]
三、查看屏幕的帮助
db2 => ? help
有关阅读帮助屏幕的指示信息:
[ ] 包括可选参数
{ } 包括必要参数
| 分隔两项或多项,只可选取其中一项
... 表示可重复的参数。
键和保留字应大写 - 它们是必要的。
例如:
CONNECT TO database-alias [IN {SHARE | EXCLUSIVE} MODE]
[USER username [USING password]]
指示下列各项为有效语句:
CONNECT TO sample
CONNECT TO sample IN SHARE MODE
CONNECT TO sample in EXCLUSIVE MODE
CONNECT TO sample IN SHARE MODE USER smith USING pw
而下列各项为无效语句:
CONNECT TO sample IN MODE (需要 SHARE 或 EXCLUSIVE )
CONNECT TO sample IN SHARE EXCLUSIVE MODE (不能使用 SHARE 和 EXCLUSIVE)
CONNECT TO sample USING pw (不能在没有用户名时使用密码)
在某些平台上,也可将 HELP 作为一个命令来访问
联机“命令参考”和 SQL Reference。
HELP 命令的语法是:
HELP [character-string]
四、查看命令选项
? OPTIONS - 关于所有命令选项的帮助
db2 => ? OPTIONS
db2 [option ...] [db2-command | sql-statement |
[? [phrase | message | sqlstate | class-code]]]
option:-a、-c、-d、-e{c|s}、-finfile、-i、-lhistfile、-m、-n、-o、
-p、-q、-rreport、-s、-t、-td;、-v、-w、-x 和 -zoutputfile。
选项 描述 缺省设置
------ ---------------------------------------- ---------------
-a 显示 SQLCA OFF
-c 自动落实 ON
-d 检索并显示 XML 声明 OFF
-e 显示 SQLCODE/SQLSTATE OFF
-f 读取输入文件 OFF
-i 显示 XML 数据并带有缩进 OFF
-l 将命令记录到历史记录文件中 OFF
-m 显示受影响的行数 OFF
-n 除去换行字符 OFF
-o 显示输出 ON
-p 显示 db2 交互式提示符 ON
-q 保留空格和换行符 OFF
-r 将输出报告保存到文件 OFF
-s 在命令出错时停止执行 OFF
-t 设置语句终止字符 OFF
-v 回传当前命令 OFF
-w 显示 FETCH/SELECT 警告消息 ON
-x 不打印列标题 OFF
-z 将所有输出保存到输出文件 OFF
注意:
使用 DB2OPTIONS 环境变量定制选项缺省值。
紧跟选项字母后的减号(-)使该选项关闭。
使用 UPDATE COMMAND OPTIONS 更改选项设置(以交互式或
文件输入方式)。
五、返回命令行处理器
db2 => quit
DB20000I QUIT命令成功完成。
六、在DB2命令行处理器直接查看命令
C:\DB291\IBM\SQLLIB\BIN>db2 ?
db2 [option ...] [db2-command | sql-statement |
[? [phrase | message | sqlstate | class-code]]]
option:-a、-c、-d、-e{c|s}、-finfile、-i、-lhistfile、-o、-m、-n、
-p、-q、-rreport、-s、-t、-td;、-v、-w、-x 和 -zoutputfile。
db2-command:
ACTIVATE DATABASE GET CONTACTS RECOVER
ADD CONTACT GET/UPDATE DB CFG REDISTRIBUTE DB PARTITION
ADD CONTACTGROUP GET/UPDATE DBM CFG REFRESH LDAP
ADD DATALINKS MANAGER GET DBM MONITOR SWITCHES REGISTER LDAP
ADD DBPARTITIONNUM GET DESCRIPTION FOR HEALTH REGISTER XMLSCHEMA
ADD XMLSCHEMA GET NOTIFICATION LIST REGISTER XSROBJECT
ARCHIVE LOG GET HEALTH SNAPSHOT REORG INDEXES/TABLE
ATTACH GET INSTANCE REORGCHK
AUTOCONFIGURE GET MONITOR SWITCHES RESET ADMIN CFG
BACKUP DATABASE GET RECOMMENDATIONS RESET ALERT CFG
BIND GET ROUTINE RESET DB CFG
CATALOG APPC NODE GET SNAPSHOT RESET DBM CFG
CATALOG APPN NODE HELP RESET MONITOR
CATALOG DATABASE HISTORY RESTART DATABASE
CATALOG DCS DATABASE IMPORT RESTORE DATABASE
CATALOG LDAP DATABASE INITIALIZE TAPE REWIND TAPE
CATALOG LDAP NODE INSPECT ROLLFORWARD DATABASE
CATALOG LOCAL NODE LIST ACTIVE DATABASES RUNCMD
CATALOG NPIPE NODE LIST APPLICATIONS RUNSTATS
CATALOG NETBIOS NODE LIST COMMAND OPTIONS SET CLIENT
CATALOG ODBC DATA SOURCE LIST DATABASE DIRECTORY SET RUNTIME DEGREE
CATALOG TCPIP NODE LIST DB PARTITION GROUPS SET TABLESPACE CONTAINERS
CHANGE DATABASE COMMENT LIST DATALINKS MANAGERS SET TAPE POSITION
CHANGE ISOLATION LEVEL LIST DBPARTITIONNUMS SET UTIL_IMPACT_PRIORITY
COMPLETE XMLSCHEMA LIST DCS APPLICATIONS SET WRITE
CREATE DATABASE LIST DCS DIRECTORY START DATABASE MANAGER
CREATE TOOLS CATALOG LIST DRDA INDOUBT START HADR
DEACTIVATE DATABASE LIST HISTORY STOP DATABASE MANAGER
DECOMPOSE XML DOCUMENT LIST INDOUBT TRANSACTIONS STOP HADR
DEREGISTER LIST NODE DIRECTORY TAKEOVER
DESCRIBE LIST ODBC DATA SOURCES TERMINATE
DETACH LIST PACKAGES/TABLES UNCATALOG DATABASE
DROP CONTACT LIST TABLESPACE CONTAINERS UNCATALOG DCS DATABASE
DROP CONTACTGROUP LIST TABLESPACES UNCATALOG LDAP DATABASE
DROP DATABASE LIST UTILITIES UNCATALOG LDAP NODE
DROP DATALINKS MANAGER LOAD UNCATALOG NODE
DROP DBPARTITIONNUM LOAD QUERY UNCATALOG ODBC DATA
DROP TOOLS CATALOG MIGRATE DATABASE UNQUIESCE DATABASE
ECHO PING UNQUIESCE INSTANCE
EDIT PREP/PRECOMPILE UPDATE ALERT CFG
EXPORT PRUNE HISTORY/LOGFILE UPDATE COMMAND OPTIONS
FORCE APPLICATION PUT ROUTINE UPDATE CONTACT
GET/UPDATE ADMIN CFG QUERY CLIENT UPDATE CONTACTGROUP
GET ALERT CFG QUIESCE DATABASE UPDATE NOTIFICATION LIST
GET AUTHORIZATIONS QUIESCE INSTANCE UPDATE HISTORY
GET/UPDATE CLI CFG QUIESCE TABLESPACES UPDATE LDAP NODE
GET CONNECTION STATE QUIT UPDATE MONITOR SWITCHES
GET CONTACTGROUP REBIND XQUERY
GET CONTACTGROUPS RECONCILE
注意:某些命令是特定于操作系统,可能不可用。
要获得进一步帮助:
? db2-command - 关于指定命令的帮助
? OPTIONS - 关于所有命令选项的帮助
? HELP - 关于阅读帮助屏幕的帮助
前面的三个选项可以在操作系统提示符下作为 db2 <option> 运行。
!db2ic - DB2 信息中心(仅用于 Windows)
此命令还可以从操作系统提示符处作为 db2ic 运行。
C:\DB291\IBM\SQLLIB\BIN>db2 ? connect
CONNECT [USER username [{USING password
[NEW new-password CONFIRM confirm-password] |
CHANGE PASSWORD}]]
CONNECT RESET
CONNECT TO database-alias
[IN {SHARE MODE | EXCLUSIVE MODE [ON SINGLE DBPARTITIONNUM]}]
[USER username [{USING password
[NEW new-password CONFIRM confirm-password] |
CHANGE PASSWORD}]]
注意:从操作系统提示符处,给命令加上“db2”前缀。
特殊字符可能需要转义序列(\),例如:
db2 \? change database
db2 ? change database xxx comment with \"text\"