Welcome 微信登录

首页 / 数据库 / MySQL / 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 isbegininsert into dept values (99, "xx_dept_name", "Beijing");end;/scott用户创建函数:create or replace function sp_fun1(spName varchar2) return number isyearSal number(7, 2);beginselect 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_infoBEFORE DELETEON empFOR EACH ROWDECLARE-- local variables hereBEGININSERT 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此时导入的只是表结构、触发器、过程、函数等这些对象,
最后验证下是否覆盖上一步已导入的表数据?
最终结论是没有覆盖已导入的表数据,之前未导入的过程、函数、触发器也都成功导入。更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12本文永久更新链接地址