oracle db_link 和触发器实现不同数据库表的同步
---创建dblink,dblink_test名称,(被同步数据库的a_test)ST10766用户名,ep密码,ass100连接字符串
create public database link dblink_test
connect to ST10766 identified by ep
using 'ass100'
---删除dblink
----drop public database link dblink_test
----建立表
create table a_test (id int,name varchar(20),pass varchar(20))
select * from a_test
insert into a_test (id,name,pass) values (1,'zzn','shanshan')
insert into b_test (id,username,password) values('1','zxl','xiaolan')
----在目的数据库上,测试dblink,查询的是源数据库的表
select * from a_test@dblink_orc10
select * from a_test
----创建触发器
create or replace trigger a_b_test
after insert or update or delete
on a_test
for each row
begin
if deleting then
delete from b_test where id=:old.id
end if
if inserting then
insert into b_test(id,username,password) //b_test表的字段
values(:new.id,:new.name,:new.pass)//a_test表的字段
end if
if updating then
update b_test set username=:new.name,password=:new.pass where id=:old.id
end if
end a_b_test
refer:https://blog.csdn.net/longshenlmj/article/details/51702343
#Hive建外部External表(外部表external table):
#
#添加分区并加载分区数据:
alter table table_name add partition (proc_date='${hivevar:pdate}') location '...'(不改变源数据存储位置)
alter table table_name add if not exsit partition (proc_date='${hivevar:pdate}') location 'hdfs://hdfscluster/'
load data inpath '...' into table table_name partition(proc_date='${hivevar:pdate}')(会将源数据切到hive表指定的路径下)
#删除分区: alter table table_name drop if exists partition(proc_date='${hivevar:pdate}')
#TBLPROPERTIES
实际上就是table properties,TBLPROPERTIES允许开发者定义一些自己的键值对信息。可以对TBLPROPERTIES进行查看和修改(部分可修改)。在TBLPROPERTIES中有一些预定义信息,比如last_modified_user和last_modified_time,其他的一些预定义信息包括:
#tplproperties属性参考
(1)comment:可以用来定义表的描述信息。
(2)hbase.table.name:hive通过 storage handler(暂放)将hive与各种工具联系起来,这是是使用hive接入hbase时,设置的属性(暂放)。
(3)immutable:顾名思义‘不可变的’,当表的这个属性为true时,若表中无数据时可以insert数据,但是当表已经有数据时,insert *** 作会失败。不可变表用来防止意外更新,避免因脚本错误导致的多次更新,而没有报错。本人实际中还没用到这个属性。
(4)orc.compress:这是orc存储格式表的一个属性,用来指定orc存储的压缩方式(暂放)。
(5) transactional,NO_AUTO_COMPACTION,compactor.mapreduce.map.memory.mb,compactorthreshold.hive.compactor.delta.num.threshold,compactorthreshold.hive.compactor.delta.pct.threshold:这5个属性与hive的事务支持有关,先不做了解。
(6)auto.purge:当设置为ture时,删除或者覆盖的数据会不经过回收站,直接被删除。配置了此属性会影响到这些 *** 作: Drop Table, Drop Partitions, Truncate Table,Insert Overwrite。
(7)EXTERNAL:通过修改此属性可以实现内部表和外部表的转化。
#
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)