Import和Load 都可以将数据导入到DB2服务器中,但是2者是有很大区别的。
Import 其实执行了SQL 的INSERT 操作。和INSERT 操作一样,Import 执行的时候会激活触发器,所有的约束会强制实现,而且会使用数据库的缓冲池。类似Oracle sql*loader工具的常规路径导入。
 
Load 工具可以更快的将数据文件导入到数据表中。Load 工具不会与DB2 数据引擎发生交互,所以当使用Load 工具时,不会触发触发器也不会使用缓冲池,而且必须单独实现数据表的约束。Import 工具执行起来比Load 慢是因为它是低层次的数据操作工具,它分
LOAD,BUILD,DELETE 三个阶段对硬盘上的数据页面来进行直接的处理。Load工具类似Oracle sql*loader工具的直接路径导入。
通过下面一个例子可以说明这一点:
db2 => connect @
   Database Connection Information
 Database server        = DB2/LINUX 9.7.0
 SQL authorization ID   = HUATENG
 Local database alias   = DBTEST
db2 => create table test(id int not null primary key,name varchar(20)) @
DB20000I  The SQL command completed successfully.
db2 => commit @
DB20000I  The SQL command completed successfully.
db2 => create trigger tri_test 
db2 (cont.) => no cascade
db2 (cont.) => before insert on test
db2 (cont.) => referencing new as n
db2 (cont.) => for each row
db2 (cont.) => begin atomic
db2 (cont.) =>    set n.name=n.name||' [import test]';
db2 (cont.) => end @
DB20000I  The SQL command completed successfully.
db2 => commit @
DB20000I  The SQL command completed successfully.
db2 => insert into test values(1,'a') @
DB20000I  The SQL command completed successfully.
db2 => commit @
DB20000I  The SQL command completed successfully.
db2 => select * from test @
ID          NAME                
----------- --------------------
          1 a [import test]    
  1 record(s) selected.
db2 => ! cat test.txt @
1,"aa"
2,"bb"
3,"cc"
4,"dd"
5,"ee"
6,"ff"
db2 => import from test.txt of del insert into test @
SQL3109N  The utility is beginning to load data from file "test.txt".
SQL3148W  A row from the input file was not inserted into the table.  SQLCODE "-803" was returned.
SQL0803N  One or more values in the INSERT statement, UPDATE statement, or foreign key update caused by a DELETE statement are not valid because the 
primary key, unique constraint or unique index identified by "1" constrains table "HUATENG.TEST" from having duplicate values for the index key.  
SQLSTATE=23505
SQL3185W  The previous error occurred while processing data from row "1" of the input file.
SQL3110N  The utility has completed processing.  "6" rows were read from the input file.
SQL3221W  ...Begin COMMIT WORK. Input Record Count = "6".
SQL3222W  ...COMMIT of any database changes was successful.
SQL3149N  "6" rows were processed from the input file.  "5" rows were successfully inserted into the table.  "1" rows were rejected.
Number of rows read         = 6
Number of rows skipped      = 0
Number of rows inserted     = 5
Number of rows updated      = 0
Number of rows rejected     = 1
Number of rows committed    = 6
db2 => select * from test @
ID          NAME                
----------- --------------------
          1 a [import test]     
          2 bb [import test]    
          3 cc [import test]    
          4 dd [import test]    
          5 ee [import test]    
          6 ff [import test]   
  6 record(s) selected.
可以看到文件中的记录1由于主键冲突而被拒绝导入,日志文件显示 Number of rows rejected     = 1 ,
其他导入的记录也都触发了触发器操作。
下面看看Load工具的情况:
db2 => delete from test where id>1 @
DB20000I  The SQL command completed successfully.
db2 => commit @
DB20000I  The SQL command completed successfully.
db2 => select * from test @
ID          NAME                
----------- --------------------
          1 a [import test]    
  1 record(s) selected.
首先删掉导入的记录,只保留ID=1的记录。
db2 => ! cat test.txt
db2 (cont.) => @
1,"aa"
2,"bb"
3,"cc"
4,"dd"
5,"ee"
6,"ff"
db2 => load from test.txt of del insert into test @
SQL3501W  The table space(s) in which the table resides will not be placed in backup pending state since forward recovery is disabled for the database.
SQL3109N  The utility is beginning to load data from file "/home/huateng/test.txt".
SQL3500W  The utility is beginning the "LOAD" phase at time "2012-03-29 06:41:44.784072".
SQL3519W  Begin Load Consistency Point. Input record count = "0".
SQL3520W  Load Consistency Point was successful.
SQL3110N  The utility has completed processing.  "6" rows were read from the input file.
SQL3519W  Begin Load Consistency Point. Input record count = "6".
SQL3520W  Load Consistency Point was successful.
SQL3515W  The utility has finished the "LOAD" phase at time "2012-03-29 06:41:44.808464".
SQL3500W  The utility is beginning the "BUILD" phase at time "2012-03-29 06:41:44.809206".
SQL3213I  The indexing mode is "REBUILD".
SQL3515W  The utility has finished the "BUILD" phase at time "2012-03-29 06:41:44.914248".
SQL3500W  The utility is beginning the "DELETE" phase at time "2012-03-29 06:41:44.952664".
SQL3509W  The utility has deleted "1" rows from the table.
SQL3515W  The utility has finished the "DELETE" phase at time "2012-03-29 06:41:44.979506".
Number of rows read         = 6
Number of rows skipped      = 0
Number of rows loaded       = 6
Number of rows rejected     = 0
Number of rows deleted      = 1
Number of rows committed    = 6
db2 => select * from test @
ID          NAME                
----------- --------------------
          1 a [import test]     
          2 bb                  
          3 cc                  
          4 dd                  
          5 ee                  
          6 ff                 
  6 record(s) selected.
很明显导入结果没有触发触发器操作,而且并没有拒绝任何行,相反的是有一条记录被删除了,这是因为Load会把所有的满足条件记录导入到表中,在 load的DELETE阶段将会删掉重复的记录行。

db2 import和load的更多相关文章

  1. db2 import export load

    DB2中所谓的数据移动,包括: 1. 数据的导入(Import) 2. 数据的导出(Export) 3. 数据的装入(Load) 导入和装入都是利用DB2的相关命令把某种格式的文件中的数据保存到数据库 ...

  2. win7 32位 安装opencv-python后,运行时提示 "from .cv2 import *: DLL load failed: 找不到指定的模块" 的解决办法

    安装opencv后,运行一个测试程序提示"from .cv2 import *: DLL load failed: 找不到指定的模块".于是百度一下解决办法,结果试了N多方法后也没 ...

  3. DB2 Z/os Load utility 使用

    Use the LOAD online utility to load one or more tables of a table space. The LOAD utility loads reco ...

  4. 【DB2】文件导入导出常见命令总结 EXPORT IMPORT LOAD

    参考文献地址:https://blog.csdn.net/reaper1022/article/details/18601973 Db2 的数据迁移,最常用的就是导入导出功能,而导入导出的命令貌似简单 ...

  5. db2 load选项

    db2 load使用 最近有个好朋友因为load问题导致了生产故障,所以特意写篇文章总结一下load的用法及注意事项. 1.load概述 数据的导入方法有insert,import和load三种,其中 ...

  6. 【DB2】db2命令Export与Import

    环境准备 1.新建表 qinys@Linux:~> db2 "create table tb1(id int,dt timestamp,name varchar(100))" ...

  7. [转]DB2 load参数

    本文持续更新,LOAD如何提高parallelism.LOAD SHRLEVEL CHANGE的性能提高. =========================== Every once in a wh ...

  8. db2基础

    DB2知识文档 一.db2 基础 基本语法 注释:"--"(两个减号) 字符串连接:"||" 如set msg='aaaa'||'bbbb',则msg为'aaa ...

  9. DB2 常用命令小结

    . 打开命令行窗口 #db2cmd . 打开控制中心 # db2cmd db2cc . 打开命令编辑器 db2cmd db2ce =====操作数据库命令===== . 启动数据库实例 #db2sta ...

随机推荐

  1. VmProtect v2.12.3 安装注冊

    执行vmprotect.exe開始安装: 1.选择语言.默觉得"English": 2.欢迎页,点"Next"到下一步: 3.授权信息,选"I acc ...

  2. Patterns-Observer

    http://book.javanb.com/java-design-patterns/index.html Java深入到一定程度,就不可避免的碰到设计模式(design pattern)这一概念, ...

  3. Global Times 单词(日常收集)

    1. 2013-09-09 windfall 英[ˈwɪndfɔ:l] 美[ˈwɪndˌfɔl] n.意外之财:被风吹落的果子:意外的收获 eg:Only half made any attempt ...

  4. Python中的迭代器漫谈

    转自:http://www.jb51.net/article/60706.htm 熟悉Python的都知道,它没有类似其它语言中的for循环, 只能通过for in的方式进行循环遍历.最典型的应用就是 ...

  5. OFBiz:组件装入位置

    默认的,OFBiz会在framework.applications.specialpurpose.hot-deploy这几个目录寻找组件,在themes目录中寻找主题.OFBiz是通过framewor ...

  6. 零基础小白怎么用Python做表格?

    用Python操作Excel在工作中还是挺常用的,因为毕竟不懂Excel是一个用户庞大的数据管理软件.本文用Python3!在给大家分享之前呢,小编推荐一下一个挺不错的交流宝地,里面都是一群热爱并在学 ...

  7. MySQL 添加外键约束,不检查现有数据

    这可能是MySQL在InnoDB中设置了foreign key关联,造成无法更新或删除数据.可以通过设置FOREIGN_KEY_CHECKS变量来避免这种情况. SET FOREIGN_KEY_CHE ...

  8. Linux命令-文件搜索命令:locate

    实际上是在分区表上搜索文件,比find命令速度更快 locate inittab 查找名称包含inittab的所有信息(快速搜索,实际上它是搜索linux资料库,区别于find在某一个磁盘分区或者某一 ...

  9. 快速掌握Gif动态图实现代码

    版权声明:本文为博主原创文章,未经博主允许不得转载. 前言:Gif一种动态图片,网上有很多制作这个的工具,包括PS都有,但作为一名程序员,我觉得如果自己通过编写代码把它实现,不但是对代码的掌握与复习, ...

  10. 分别用C和C++来实现一个链栈

    下面通过分别用C和C++来实现一个链栈(链表实现),从中体会数据封装抽象的思想: C语言实现:  C++ Code  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ...