Oracle数据库验证IMP导入元数据是否会覆盖历史表数据
场景:imp导入数据时,最终触发器报错退出,并未导入存储过程、触发器、函数。
现在exp单独导出元数据,然后imp导入元数据,验证是否会影响已导入的表数据。
测试环境:CentOS 6.7 + Oracle 11.2.0.4
构造实验环境:
- 1.导出scott用户的表和数据
- 2.scott用户创建过程、函数、触发器
- 3.导出scott元数据
- 4.删除scott用户
- 5.导入scott表和数据
- 6.导入Scott元数据
1.导出scott用户的表和数据
导出scott用户的表和数据,此时并没有触发器、过程、函数这些对象:
exp scott/tiger OWNER=scott BUFFER=10240000 STATISTICS=none RESUMABLE=y FILE=scott_exp.dmp LOG=scott_exp.log
2.scott用户创建过程、函数、触发器
scott用户创建过程:
create or replace procedure pro_insert_dept is begin insert into dept values (99, 'xx_dept_name', 'Beijing'); end; /
scott用户创建函数:
create or replace function sp_fun1(spName varchar2) return number is yearSal number(7, 2); begin select sal * 12 + nvl(comm, 0) * 12 into yearSal from emp where ename = spName; return yearSal; end; /
scott用户触发器:
--创建序列
CREATE SEQUENCE seq_del_id;
--创建表
CREATE TABLE emp_del_info(
autoid number primary key,
deptno number,
empno number,
ename varchar2(20),
del_rq date);
--创建触发器
CREATE OR REPLACE TRIGGER trg_del_emp_info
  BEFORE DELETE
  ON emp
  FOR EACH ROW
  DECLARE
    -- local variables here
  BEGIN
    INSERT INTO emp_del_info(autoid,deptno,empno,ename,del_rq)
          VALUES(seq_del_id.NEXTVAL,:OLD.deptno,:OLD.empno,:OLD.ename,sysdate);
  END;
/3.导出scott元数据
导出scott元数据:
exp scott/tiger OWNER=scott ROWS=n BUFFER=10240000 STATISTICS=none RESUMABLE=y FILE=scott_metadata_exp.dmp LOG=scott_metadata_exp.log
此时导出的元数据,是有触发器、过程、函数这些对象的。
4.删除scott用户
确认没有scott用户登录的session:
select 'alter system kill session '''||sid||','||serial#||''''||';' from v$session where username='SCOTT';
如果上述查询有结果,那么直接把查出的结果复制执行即可kill掉scott用户登录的session。
删除scott用户:
SQL> drop user scott cascade; User dropped.
5.导入scott表和数据
先创建用户并赋权:
SQL> create user scott identified by tiger default tablespace users; User created. SQL> grant connect, resource to scott; Grant succeeded.
导入表和数据:
imp scott/tiger BUFFER=10240000 RESUMABLE=y FILE=scott_exp.dmp LOG=imp_scott_exp.log IGNORE=y FULL=y
此时导入的只是表和表数据,没有触发器、过程、函数这些对象。
6.导入Scott元数据
imp scott/tiger BUFFER=10240000 RESUMABLE=y FILE=scott_metadata_exp.dmp LOG=imp_scott_metadata_exp.log IGNORE=y FULL=y
此时导入的只是表结构、触发器、过程、函数等这些对象,
最后验证下是否覆盖上一步已导入的表数据?
最终结论是没有覆盖已导入的表数据,之前未导入的过程、函数、触发器也都成功导入。
相关推荐
  txj    2020-09-08  
   zyshappy    2020-08-16  
   vipiter    2020-07-16  
   shurenyun    2020-06-21  
   inabaraku    2020-06-12  
   李战磊    2020-06-10  
   阿亮    2020-06-10  
   wannagonna    2020-06-08  
   LUOPING0    2020-06-03  
   liwenshui    2020-06-02  
   meleto    2020-05-30  
   LychieFan    2020-05-18  
   zzjmay    2020-05-17  
   neverstopforcode    2020-05-14  
   zhangskd    2020-05-05  
   东哥笔记    2020-04-29  
   wangrui0    2020-04-26  
 