您的位置:首页 > 数据库 > Oracle

Oracle得知(十五):分布式数据库

2015-10-10 10:31 459 查看


--分布式数据库的独立性:分布数据的独立性指用户不必关心数据怎样切割和存储,仅仅需关心他须要什么数据。

--本地操作
SQL> sqlplus scott/tiger
--远程操作
SQL> sqlplus scott/tiger@192.168.1.217:1521/orcl

--分布式操作

SQL> --创建数据库链路l2(须要权限);
SQL> --remoteorcl服务命名(在net manager里配置):配置跟远程server的数据库的连接协议、主机名(ip地址)、port号等
SQL> create database link l2 connect to scott identified by tiger using 'remoteorcl';
SQL> --在分布式数据库中运行查询
SQL> select ename,dname
2  from dept, emp@L2	--通过数据库链路L2查询emp表
3  where emp.deptno=dept.deptno;

SQL> --为emp@L2创建同义词
SQL> create SYNONYM remoteemp for emp@L2;
SQL> --使用同义词进行查询
SQL> select ename,dname
2  from dept, remoteemp	--使用同义词
3  where remoteemp.deptno=dept.deptno;

create view emp
as
select * from emp1@L1	--指向上海的链路
union
select * from emp2@L2; --指向北京的链路

select * from emp; --从上海和北京的数据库查询

--分布式数据库的跨界点更新:快照;触发器。
--快照:定义快照维护关系表的异步副本(创建在备份端)
--指在主表改动后的指定时间内刷新副本,用于主表改动少。但频繁查询的表
create snapshot emp	--创建快照
refresh start with sysdate		--第一次更新
next next_day(sysdate,’Monday’)	--下次更新时间
as select * from emp@L1;	--更新内容

--触发器(创建在主数据库上)
SQL> --利用触发器实现数据的同步更新(以下的代码仅仅实现了薪水更新触发器)
SQL> create or replace trigger syncsal
2  after update
3  on emp
4  for each row
5  begin
6  	update remoteemp set sal=:new.sal where empno=:new.empno;
7
8  end;
9  /
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: