参数说明:
-a: Generate statistics for all creators
-e: Extract DDL file needed to duplicate database
-x: Generate Authorization statements DDL excluding the original definer of the object
注: 对于不同系统 如 linux unix与windows的移动来说
使用BACKUP/RESTORE命令显然是不行
db2move命令没有办法迁移索引、外键约束、触发器,更不能迁移含自增字段数据的表
这种情况下建议用第三种情况进行。
3) 使用下面的SQL语句生成导出所有数据的脚本:exort.sql
db2 "select 'export to ' || rtrim(tabname) || '.ixf of ixf select * from ' || rtrim(tabname) || ';' from syscat.tables where tabschema = 'DB2INST1'" > export.sql
4) 编辑生成的export.sql,把头和尾那些信息去掉,只保留必要的export命令.
5) 使用下面的SQL语句生成倒入所有数据的脚本(我们使用LOAD命令,而且必须使用)
db2 "select 'load from ' || rtrim(tabname) || '.ixf of ixf insert into ' || rtrim(tabname) || ';' from syscat.tables where tabschema = 'DB2INST1'" > load.sql
6) 编辑生成的load.sql,把头和尾的信息去掉,只保留必要的load命令.搜索sample_tabs.ddl文件中哪些表含有自增字段(含有GENERATED ALWAYS AS IDENTITY定义的字段的表),并把load.sql中含有自增字段的表的load命令加入modified by identityoverride语句(加在of ixf和 insert之间,例如: load from MYTABLE.ixf of ixf modified by identityoverride insert into MYTABLE;)
注意:load命令中的modified by identityoverride可以保证导入数据时那些自增字段的值和原数据库中的数据一致.