当前位置:数据库 > SQLServer >>

db2 sql

 

DB2/SQL命令大全2006-12-25 13:21连接数据库:

  connect to [数据库名] user [操作用户名] using [密码]

创建缓冲池(8K):

  create bufferpool ibmdefault8k IMMEDIATE  SIZE 5000 PAGESIZE 8 K ;

创建缓冲池(16K)(OA_DIVERTASKRECORD):

  create bufferpool ibmdefault16k IMMEDIATE  SIZE 5000 PAGESIZE 16 K ;

创建缓冲池(32K)(OA_TASK):

  create bufferpool ibmdefault32k IMMEDIATE  SIZE 5000 PAGESIZE 32 K ;

创建表空间:

  CREATE TABLESPACE exoatbs IN DATABASE PARTITION GROUP IBMDEFAULTGROUP PAGESIZE 8K MANAGED BY SYSTEM USING ('/home/exoa2/exoacontainer') EXTENTSIZE 32 PREFETCHSIZE 16  BUFFERPOOL IBMDEFAULT8K  OVERHEAD 24.10 TRANSFERRATE 0.90  DROPPED TABLE RECOVERY OFF;

 

  CREATE TABLESPACE exoatbs16k  IN DATABASE PARTITION GROUP IBMDEFAULTGROUP PAGESIZE 16K MANAGED BY SYSTEM USING ('/home/exoa2/exoacontainer16k'   ) EXTENTSIZE 32  PREFETCHSIZE 16  BUFFERPOOL IBMDEFAULT16K  OVERHEAD 24.1 TRANSFERRATE 0.90  DROPPED TABLE RECOVERY OFF;

  CREATE TABLESPACE exoatbs32k  IN DATABASE PARTITION GROUP IBMDEFAULTGROUP PAGESIZE 32K MANAGED BY SYSTEM USING ('/home/exoa2/exoacontainer32k'   ) EXTENTSIZE 32  PREFETCHSIZE 16  BUFFERPOOL IBMDEFAULT32K  OVERHEAD 24.1 TRANSFERRATE 0.90  DROPPED TABLE RECOVERY OFF;

GRANT USE OF TABLESPACE exoatbs TO PUBLIC;

GRANT USE OF TABLESPACE exoatbs16k TO PUBLIC;

GRANT USE OF TABLESPACE exoatbs32k TO PUBLIC;

创建系统表空间:

  CREATE TEMPORARY TABLESPACE exoasystmp IN DATABASE PARTITION GROUP IBMTEMPGROUP PAGESIZE 8K  MANAGED BY SYSTEM USING ('/home/exoa2/exoasystmp'   ) EXTENTSIZE 32 PREFETCHSIZE 16 BUFFERPOOL IBMDEFAULT8K  OVERHEAD 24.10 TRANSFERRATE 0.90  DROPPED TABLE RECOVERY OFF;

  CREATE TEMPORARY TABLESPACE exoasystmp16k IN DATABASE PARTITION GROUP IBMTEMPGROUP PAGESIZE 16K MANAGED BY SYSTEM USING ('/home/exoa2/exoasystmp16k'  ) EXTENTSIZE 32 PREFETCHSIZE 16 BUFFERPOOL IBMDEFAULT16K OVERHEAD 24.10 TRANSFERRATE 0.90  DROPPED TABLE RECOVERY OFF;

  CREATE TEMPORARY TABLESPACE exoasystmp32k IN DATABASE PARTITION GROUP IBMTEMPGROUP PAGESIZE 32K MANAGED BY SYSTEM USING ('/home/exoa2/exoasystmp32k') EXTENTSIZE 32 PREFETCHSIZE 16 BUFFERPOOL IBMDEFAULT32K OVERHEAD 24.10 TRANSFERRATE 0.90  DROPPED TABLE RECOVERY OFF;

1. 启动实例(db2inst1):

db2start

2. 停止实例(db2inst1):

db2stop

3. 列出所有实例(db2inst1)

db2ilist

5.列出当前实例:

db2 get instance

4. 察看示例配置文件:

db2 get dbm cfg|more

5. 更新数据库管理器参数信息:

db2 update dbm cfg using para_name para_value

6. 创建数据库:

db2 create db test

7. 察看数据库配置参数信息

db2 get db cfg for test|more

8. 更新数据库参数配置信息

db2 update db cfg for test using para_name para_value

10.删除数据库:

db2 drop db test

11.连接数据库

db2 connect to test

12.列出所有表空间的详细信息。

db2 list tablespaces show detail

13.查询数据:

db2 select * from tb1

14.删除数据:

db2 delete from tb1 where id=1

15.创建索引:

db2 create index idx1 on tb1(id);

16.创建视图:

db2 create view view1 as select id from tb1

17.查询视图:

db2 select * from view1

18.节点编目

db2 catalog tcp node node_name remote server_ip server server_port

19.察看端口号

db2 get dbm cfg|grep SVCENAME

20.测试节点的附接

db2 attach to node_name

21.察看本地节点

db2 list node direcotry directory

22.节点反编目

db2 uncatalog node node_name

23.数据库编目

db2 catalog db db_name as db_alias at node node_name

24.察看数据库的编目

db2 list db directory

25.连接数据库

db2 connect to db_alias user user_name using user_password

26.数据库反编目

db2 uncatalog db db_alias

27.导出数据

db2 export to myfile of ixf messages msg select * from tb1

28.导入数据

db2 import from myfile of ixf messages msg replace into tb1

29.导出数据库的所有表数据

db2move test export   //远程链接的db2move test export -u username -p password

 

30.生成数据库的定义

db2look -d db_alias -a -e -m -l -x -f -o db2look.sql   

//远程链接的db2look -d db_alias -a -e -m -l -x -f -o db2look.sql  -i username -w password

31.创建数据库

db2 create db test1

32.生成定义

db2 -tvf db2look.sql

33.导入数据库所有的数据

db2move db_alias import

34.重组检查

db2 reorgchk

35.重组表tb1

db2 reorg table tb1

36.更新统计信息

db2 runstats on table tb1

37.备份数据库test

db2 backup db test

38.恢复数据库test

db2 restore db test

399\.列出容器的信息

db2 list tablespace containers for tbs_id show detail

40.创建表:

db2 ceate table tb1(id integer not null,name char(10))

41.列出所有表

db2 list tables

42.插入数据:

db2 insert into tb1 values(1,’sam’);

db2 insert into tb2 values(2,’smitty’);

. 建立数据库DB2_GCB

CREATE DATABASE DB2_GCB ON G: ALIAS DB2_GCB

USING CODESET GBK TERRITORY CN COLLATE USING SYSTEM DFT_EXTENT_SZ 32

2. 连接数据库

connect to sample1 user db2admin using 8301206

3. 建立别名

create alias db2admin.tables for sysstat.tables;

CREATE ALIAS DB2ADMIN.VIEWS FOR SYSCAT.VIEWS

create alias db2admin.columns for syscat.columns;

create alias guest.columns for syscat.columns;

4. 建立表

create table zjt_tables as

(select * from tables) definition only;

create table zjt_views as

(select * from views) definition only;

5. 插入记录

insert into zjt_tables select * from tables;

insert into zjt_views select * from views;

6. 建立视图

create view V_zjt_tables as select tabschema,tabname from zjt_tables;

7. 建立触发器

CREATE TRIGGER zjt_tables_del

AFTER DELETE ON zjt_tables

REFERENCING OLD AS O

FOR EACH ROW MODE DB2SQL

Insert into zjt_tables1 values(substr(o.tabschema,1,8),substr(o.tabname,1,10))

8. 建立唯一性索引

CREATE UNIQUE INDEX I_ztables_tabname

[size=3]ON zjt_tables(tabname);

9. 查看表

select tabname from tables

where tabname='ZJT_TABLES';

10. 查看列

select SUBSTR(COLNAME,1,20) as 列名,TYPENAME as 类型,LENGTH as 长度

from columns

where tabname='ZJT_TABLES';

11. 查看表结构

db2 describe table user1.department

db2 describe select * from user.tables

12. 查看表的索引

db2 describe indexes for table user1.department

13. 查看视图

select viewname from views

where viewname='V_ZJT_TABLES';

14. 查看索引

select indname from indexes

where indname='I_ZTABLES_TABNAME';

15. 查看存贮过程

SELECT SUBSTR(PROCSCHEMA,1,15),SUBSTR(PROCNAME,1,15)

FROM SYSCAT.PROCEDURES;

16. 类型转换(cast)

ip datatype:varchar

select cast(ip as integer)+50 from log_comm_failed

17. 重新连接

connect reset

18. 中断数据库连接

disconnect db2_gcb

19. view application

LIST APPLICATION;

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,