2011年1月18日

同步不同 DB 的 Table -- 設定/取消 Oracle 的 Synonym 連結

公司有時需要每一個資料庫的 Table 都參考到 ds 或是母公司的資料庫,
像是權限管理預設就是 zx_file、zy_file、zw_file 都參考 ds 的資料庫,

因此要如何設定 Synonym 呢??

1. 先把原本的 table 刪除
    drop table xxx_file;

2. 再建立 synonym
    CREATE OR replace synonym DBUSER.xxx_file for ds.xxx_file;

那如果是要取消 synonym 呢??

1. 先把原本的 synonym 取消
    drop synonym  DBUSER.xxx_file;

2. 再把 table 建立回來,再加上設定為 PUBILC 可以讓其他 user 存取
    (使用 DB table 複製的功能會比較快)
    create table DBUSER.xxx_file as select * from ds.xxx_file where rownum = 1;
    delete DBUSER.xxx_file;
    grant all on sfa_file to public;

沒有留言:

張貼留言