db2 常用命令1

上传人:小** 文档编号:89124615 上传时间:2019-05-18 格式:DOC 页数:7 大小:25KB
返回 下载 相关 举报
db2 常用命令1_第1页
第1页 / 共7页
db2 常用命令1_第2页
第2页 / 共7页
db2 常用命令1_第3页
第3页 / 共7页
db2 常用命令1_第4页
第4页 / 共7页
db2 常用命令1_第5页
第5页 / 共7页
点击查看更多>>
资源描述

《db2 常用命令1》由会员分享,可在线阅读,更多相关《db2 常用命令1(7页珍藏版)》请在金锄头文库上搜索。

1、DB2 常用命令1启动DB2服务:db2start关闭DB2服务: db2stop一、加载数据:1、 以默认分隔符加载,默认为“,”号 db2 import from btpoper.txt of del insert into btpoper2、 以指定分隔符“|”加载 db2 import from btpoper.txt of del modified by coldel| insert into btpoperimport from import.txt of del modified by coldel | insert into ts_tcqs_rhjgbimport from i

2、mport.txt of del modified by coldel: insert into ts_tcqs_rhjgb二、卸载数据:1、 卸载一个表中全部数据 db2 export to btpoper.txt of del select * from btpoper db2 export to btpoper.txt of del modified by coldel| select * from btpoper export to export2.txt of del modified by coldel: select * from ts_tcqs_xtztb2、 带条件卸载一个表

3、中数据 db2 export to btpoper.txt of del select * from btpoper where brhid=907020000 db2 export to cmmcode.txt of del select * from cmmcode where codtp=01 db2 export to cmmcode.txt of del modified by coldel| select * from cmmcode where codtp=01三、查询数据结构及数据: db2 select * from btpoper db2 select * from btp

4、oper where brhid=907020000 and oprid=0001 db2 select oprid,oprnm,brhid,passwd from btpoper四、删除表中数据: db2 delete from btpoper db2 delete from btpoper where brhid=907020000 or brhid=907010000五、修改表中数据: db2 update svmmst set prtlines=0 where brhid=907010000 and jobtp=02 db2 update svmmst set prtlines=0 w

5、here jobtp=02 or jobtp=03六、联接数据库 db2 connect to btpdbs七、清除数据库联接 db2 connect reset 断开数据库连接 db2 terminate 断开数据库连接 db2 force applications all 断开所有数据库连接八、备份数据库1、 db2 backup db btpdbs2、 db2move btpdbs export db2look -d btpdbs -e -x -a -o crttbl.sql九、恢复数据库1、 db2 restore db btpdbs without rolling forward2、

6、 db2 -tvf crtdb.sql crtdb.sql文件内容:create db btpdbs on /db2catalog db2 -stvf crttbl.sql db2move btpdbs import十、DB2帮助命令: db2 ? db2 ? restroe db2 ? sqlcode (例:db2 ? sql0803) 注:code必须为4位数,不够4位,前面补0十一、bind命令:将应用程序与数据库作一捆绑,每次恢复数据库后,建议都要做一次bind (1) db2 bind br8200.bnd (2) /btp/bin/bndall /btp/bnd /btp/bin/

7、bndall /btp/tran/bnd十二、查看数据库参数: db2 get dbm cfg db2 get db cfg for btpdbs十三、修改数据库参数: db2 update db cfg for btpdbs using LOGBUFSZ 20 db2 update db cfg for btpdbs using LOGFILSIZ 5120 改完后,应执行以下命令使其生效: db2 stop db2 start十四、进入命令行 db2 退出命令行 quit十五、查找表中的重复记录: select id from hb_vipuserinfo where id in (sel

8、ect id from hb_vipuserinfo group by id having count(id) 1); 十六、删除表中的重复记录,并保留rowid最小的记录(适合ORACLE): delete from hb_vipuserinfo where id in (select id from hb_vipuserinfo group by id having count(id ) 1) and rowid not in (select min(rowid) from hb_vipuserinfo group by id having count(id ) 1); 十七、删除重复数据

9、 insert into tps_user_menu_old select * from tps_user_menu; insert into tps_user_menu_new SELECT * FROM tps_user_menu GROUP BY usercode, menuid HAVING COUNT(DISTINCT usercode)=1; 补充: db2 set schema btp 修改当前模式为btp db2 list tablespaces show detail 查看当前数据库表空间分配状况 db2 list tablespace containers for 2 sh

10、ow detail 查看tablespace id=2使用容器所在目录 db2 list application db2 list db directory 列出所有数据库 db2 list active databases 列出所有活动的数据库 db2 list tables for all 列出当前数据库下所有的表 db2 list tables for schema btp 列出当前数据库中schema为btp的表 db2 list tablespaces show detail 显示数据库空间使用情况 db2 list packages for all db2 import from

11、tab76.ixf of ixf commitcount 5000 insert into achact db2 create table achact_t like achact db2 rename table achact_t to achact db2 insert into achact_t select * from achact where txndt=(select lstpgdt from acmact where actno=achact.actno) db2 get snapshot for dynaimic sql on jining删除一个实例: # cd /usr/

12、lpp/db2_07_01/instance # ./db2idrop InstName列出所有DB2实例: # cd /usr/lpp/db2_07_01/bin # ./db2ilist为数据库建立编目 $ db2 catalog db btpdbs on /db2catalog取消已编目的数据库btpdbs $ db2 uncatalog db btpdbs查看版本 # db2level显示当前数据库管理实例 $ db2 get instance设置实例系统启动时是否自动启动。 $ db2iauto -on 自动启动 $ db2iauto -off 不自动启动数据库优化命令: reorg

13、、runstats 当数据库经过一段时间使用,数据空间会变得越来越庞大。一些delete掉 的数据仍存放在数据库中,占用数据空间,影响系统性能。因此需要定期 运行reorg、runstats命令,清除已delete的数据,优化数据结构。 db2 reorg table 表名 db2 runstats on table 表名 with distribution and indexes all 因为要优化的表比较多,所以在/btp/bin目录下提供了一个sh程序runsall, 可在当天业务结束后,运行runsall,对数据库进行优化 db2 CONNECT TO TMS;db2 QUIESCE

14、DATABASE IMMEDIATE FORCE CONNECTIONS;db2 CONNECT RESET;db2 BACKUP DATABASE TMS TO /home/trade/as WITH 2 BUFFERS BUFFER 1024 PARALLELISM 1 WITHOUT PROMPTING;db2 CONNECT TO TMS;db2 UNQUIESCE DATABASE;db2 CONNECT RESET;DB2数据库还原:db2 RESTORE DATABASE TMS FROM /home/trade TAKEN AT 20090518022939 WITH 2 BUFFERS BUFFER 1024

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 商业/管理/HR > 管理学资料

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号