DB2 Environment introduction(DB2环境介绍).
DB2 environment have four part(DB2环境由四部分构成).
1. Profile Registry(概要文件注册表);
2. Environment variable(环境变量);
3. Instance configuration file(实例配置文件);
4. Database configuration file(数据库配置文件).
Start DB2 command window.(启动db2命令窗口。)
db2cmd
INSTANCE LEVEL COMMAND(实例级命令)
1. db2icrt
Description(描述):
Used to create a instance.(用于创建一个DB2实例,DB2实例是用于执行DB2命令和函数所处的上下文。
可以把实例看做管理对数据库文件的访问权的服务或守护进程。DB2中一台服务器可以有多个实例,每个实例相互独立,
但同一时刻只能有一个实例在运行。)
Systax(语法):
db2icrt instance_name
linux need to provide user id for create function and storage procedure.(Linux 中必须提供用于创建函数和存储过程的用户标识。)
db2icrt -u fenced_user_ID instance_name
Examples(例子):
db2icrt NEW
2. db2idrop
Description(描述):
Drop a db2 instance(删除一个DB2实例)。
Before drop a instance, you should disconnect all the database connection and stop current db2 instance.
Systax(语法):
db2idrop -f intance_name
Examples(例子):
db2idrop -f NEW
3. db2start
Description(描述):
Start the current db2 instance.(启动当前的DB2实例。)
Systax(语法):
db2start
Examples(例子):
db2start
4. db2stop
Description(描述):
Stop the current db2 instance.(停止当前的DB2实例。)
Systax(语法):
db2stop
Examples(例子):
db2stop
5. db2 get instance
Description(描述):
Get the current db2 instance, the value of environment db2instance.(获得当前所运行的DB2实例名称,环境变量db2instance的值。)
Systax(语法):
db2 get instance
Examples(例子):
db2 get instance
6. set db2instance
Description(描述):
Set the current db2 instance.(设置环境变量db2instance的值。)
Systax(语法):
Windows: set db2instance=instance_name;
Unix C Shell: setenv db2instance instance_name;
Unix Korn Shell: export db2instance=instance_name;
Examples(例子):
set db2instance=NEW
7. db2 get dbm cfg
Description(描述):
Each db2 instance has a configuration file.(每个DB2实例有一个数据库管理配置文件,这个文件用于保存与认证,监管级别,诊断级别,
以及贯穿实例的内存和进程资源有关的参数。当更新这个文件后需要重新启动实例。)
Systax(语法):
db2 get dbm cfg
Examples(例子):
db2 get dbm cfg
8. db2 update dbm cfg
Description(描述):
Systax(语法):
db2 update dbm cfg using PARAMETER_NAME PARAMETER_VALUE
Examples(例子):
db2 update dbm cfg using DIAGLEVEL 4
db2stop
db2start
9. db2imigr
Description(描述):
When you install a new version of DB2 UDB, you need to migrate instance.
Systax(语法):
db2imigr instance_name
Examples(例子):
db2imigr NEW
10. db2iupdt
Description(描述):
When you install a new version of DB2 UDB, you need to update instance.
Systax(语法):
db2iupdt instance_name
Examples(例子):
db2iupdt NEW
11. db2ilist
Description(描述):
List all the db2 instance in the server.(列出服务器上的所有的db2实例。)
Systax(语法):
db2ilist
Examples(例子):
db2ilist
12. db2 attach to
Description(描述):
Connect a db2 instance in the server from remote computer.(远程连接db2实例。)
Systax(语法):
ATTACH [TO node-name] [USER username [{USING password[NEW new-password CONFIRM confirm-password] |CHANGE PASSWORD}]]
Examples(例子):
db2 attach to NEW
13. db2 list applications
Description(描述):
List all the connection to the currenct db2 instance.(列出所有与当前db2实例的连接。)
Systax(语法):
db2 list applications [show detail]
Examples(例子):
db2 list applications [show detail]
14. db2 force application
Description(描述):
Stop the connection to the currenct db2 instance.(断开与当前db2实例的连接。)
Systax(语法):
FORCE APPLICATION {ALL | ( application-handle [ {,application-handle} ... ] )}[MODE ASYNC]
Examples(例子):
db2 db2 force application (6, 5)
db2 force application all
DAS INSTANCE COMMAND(DAS实例命令)
DAS a special instance, it is short for Database Administrator Server. Only one DAS can be create in one DB2 server.
DAS provide local&remote management function.(DAS是一个特殊的实例,只能有一个DAS驻留在db2服务器上,DAS允许使用db2工具对
服务器进行本地和远程管理。)
1. dbsicrt(db2admin create)
Description(描述):
DAS was created automatically when db2 installing.(DAS通常在安装时候自动创建。)
Systax(语法):
UNIX:dasicrt name
WINDOWS:db2admin create
Examples(例子):
UNIX:dasicrt MyDas
WINDOWS:db2admin create
2. dbsidrop(db2admin drop)
Description(描述):
Systax(语法):
UNIX:dbsidrop name
WINDOWS:db2admin drop
Examples(例子):
UNIX:dbsidrop MyDas
WINDOWS:db2admin drop
3. db2admin start
Description(描述):
Start DAS.(启动DAS。)
Systax(语法):
db2admin start
Examples(例子):
db2admin start
4. db2admin stop
Description(描述):
Stop DAS.(停止DAS。)
Systax(语法):
db2admin stop
Examples(例子):
db2admin stop
5. db2 get admin cfg
Description(描述):
Get DAS configuration information.(取得DAS配置信息。)
Systax(语法):
db2 get admin cfg
Examples(例子):
db2 get admin cfg
6. db2 update admin cfg
Description(描述):
Update DAS configuration information.(更新DAS配置信息。)
Systax(语法):
db2 update admin cfg using PARAMETER_NAME PARAMETER_VALUE
Examples(例子):
db2 update admin cfg using DIAGLEVEL 4
Profile Registry Command(概要文件注册表命令)
1. db2set -lr
Description(描述):
List out all the supportive parameter name.(列出所受支持的概要文件注册表。)
Systax(语法):
db2set -lr
Examples(例子):
db2set -lr
2. db2set registry_variable=value
Description(描述):
Set registry variable.(设置DB2概要文件注册表。)
Systax(语法):
db2set registry_variable=value
Examples(例子):
db2set DB2COMM=TCPIP,APPC
3. db2set registry_variable=
Description(描述):
Set registry variable to default value .(恢复DB2概要文件注册表默认值。)
Systax(语法):
db2set registry_variable=
Examples(例子):
db2set DB2COMM=
4. db2set -all
Description(描述):
List out all the settled registry variable value.(列出所受支持的概要文件注册表。)
Systax(语法):
db2set -all
Examples(例子):
db2set -all
DATABASE LEVEL COMMAND(数据库级别命令)
1. db2 ?
Description(描述):
Ask help.(查询帮助文档。)
Systax(语法):
db2 [option ...] [db2-command | sql-statement |
[? [phrase | message | sqlstate | class-code]]]
Examples(例子):
db2 ?
db2 ? disconnect
2. db2 connect to
Description(描述):
Connect database.(连接数据库。)
Systax(语法):
CONNECT TO database-alias
[IN {SHARE MODE | EXCLUSIVE MODE [ON SINGLE DBPARTITIONNUM]}]
[USER username [{USING password
[NEW new-password CONFIRM confirm-password] |
CHANGE PASSWORD}]]
Examples(例子):
db2 connect to sample user aa using 123456
db2 connect to sample user aa using 123456 new 654321 confirm 654321
3. db2 connect reset
Description(描述):
Reonnect database.(重新连接数据库。)
Systax(语法):
db2 connect reset
Examples(例子):
db2 connect reset
4. db2 disconnect
Description(描述):
Disonnect database.(断开数据库连接。)
Systax(语法):
DISCONNECT { server-name | CURRENT | ALL [SQL] }
Examples(例子):
db2 disconnect sample
db2 disconnect current
db2 disconnect all
5. db2 list
Description(描述):
Show database information.(查看数据库。)
Systax(语法):
db2 list tablespaces [show detail]
Examples(例子):
db2 list db directory
db2 list tables
db2 list tablespaces
6. db2 create database
Description(描述):
Create database.(创建数据库。)
Systax(语法):
CREATE DATABASE database-name
[AT DBPARTITIONNUM | [ON drive] [ALIAS database-alias]
[USING CODESET codeset TERRITORY territory]
[COLLATE USING {SYSTEM | IDENTITY | IDENTITY_16BIT | COMPATIBILITY | NLSCHAR}]
[NUMSEGS numsegs] [DFT_EXTENT_SZ dft_extentsize]
[CATALOG TABLESPACE tblspace-defn]
[USER TABLESPACE tblspace-defn]
[TEMPORARY TABLESPACE tblspace-defn]
[WITH "comment-string"]]
[AUTOCONFIGURE [USING config-keyword value [{,config-keyword value}...]]
[APPLY {DB ONLY | DB AND DBM | NONE}]]
Examples(例子):
create database mydb on C: using codeset GBK territory cn
7. db2 drop database
Description(描述):
Delete database.(删除数据库。)
Systax(语法):
DROP DATABASE database-alias [AT DBPARTITIONNUM]
Examples(例子):
drop database mydb
8. db2 get db cfg
Description(描述):
Get database configuration information.(取得数据库配置信息。)
Systax(语法):
db2 get db cfg
Examples(例子):
db2 get db cfg
9. db2 update db cfg
Description(描述):
Update database configuration information.(更新数据库配置信息。)
Systax(语法):
db2 update db cfg using PARAMETER_NAME PARAMETER_VALUE
Examples(例子):
db2 update db cfg using DIAGLEVEL 4
DDL(Data Definition Language 数据定义语言)
Use create statement to create database object.(使用CREATE语句创建新的数据库对象。)
a. Buffer Pool(缓冲池)
b. Event monitor(事件监视器)
c. Funcition(函数)
d. Index(索引)
e. Schema(模式)
f. Stored Procedure(存储过程)
g. Table(表)
h. Trigger(触发器)
i. View(视图)
1. db2 create table
Description(描述):
Create table.(创建表。)
Systax(语法):
CREATE TABLE table_name
( element_name element_type [CONSTRAINT],
element_name element_type [CONSTRAINT],
element_name element_type [CONSTRAINT],
element_name element_type [CONSTRAINT],
....,
CONSTRAINT constraint_name PRIMARY KEY (element_name))
Examples(例子):
db2 create table code_page(Alphabet varchar(120), codepage integer not null, constraint new_pk primary key (codepage))
2. db2 drop table
Description(描述):
Delete table.(删除表。)
Systax(语法):
DROP TABLE table_name
Examples(例子):
drop table code_page
DML(Data Manipulation Language数据操作语言)
1. db2 select
Description(描述):
Select data from table.(检索表中数据。)
Systax(语法):
SELECT column_names FROM table_name
WHERE ...LIKE/IN/
GROUP BY ... HAVING...
ORDER BY
FETCH FIRST number ROWS[ROW] ONLY
Examples(例子):
db2 select * from code_page where codepage > 100 fetch first 10 rows only
db2 select * from code_page where Alphabet like '%erma??' fetch first 10 rows only
2. db2 insert
Description(描述):
Insert data into table.(向表中插入数据。)
Systax(语法):
INSERT INTO table_name[(column_names)] VALUES(value_list)
Examples(例子):
db2 insert into T2 select * from t1
db2 insert into code_page(Alphabet, codepage) values('IA5 (German)', 20106)
3. db2 update
Description(描述):
Update data in table.(更新表中数据。)
Systax(语法):
UPDATE table_name
SET (column_names) =(value_list)
WHERE...
Examples(例子):
db2 update code_page set Alphabet='abc' where codepage=20106
4. db2 delete
Description(描述):
Delete data in table.(删除表中数据。)
Systax(语法):
DELETE FROM table_name
WHERE...
Examples(例子):
db2 delete from code_page where codepage=20106
db2 delete from code_page
5. db2 -f file_name
Description(描述):
Run the sql script from a file.(运行sql脚本文件。)
Systax(语法):
db2 -f file_name
WHERE...
Examples(例子):
db2 -f c:\a.sql
6. db2 select * from table > file_name
Description(描述):
Redirect the result of query to a file.(将查询结果导入文件中。)
Systax(语法):
db2 select * from table > file_name
WHERE...
db2 select * from code_page > c:\code_page.txt
Database Maintennace(数据库维护)
1. export
Description(描述):
Export data from database to a DEL/IXF/WSF file.(将数据库中数据导入文件中。)
Systax(语法):
EXPORT TO file_name OF [DEL/IXF/WSF] SELECT ... FROM X...
WHERE...
export to c:\code_page.del of del select * from code_page
2. import
Description(描述):
Import data to database from file.(将数据从文件导入到数据库中。)
Systax(语法):
IMPORT FROM file_name OF [DEL/IXF/WSF] [INSERT/INSERT_UPDATE/REPLACE/REPLACE_CREATE/CREATE] INTO table_name
WHERE...
import from c:\code_page.del of del insert into code_page