Oracle 同義字synonym 學習

來源:互聯網
上載者:User

同義字:從字面上理解就是別名的意思,和試圖的功能類似。就是一種映射關係。

(1.建立同義字語句:

   create public synonym table_name for user.table_name;

  其中第一個 table_name和第二個 table_name 可以不一樣。

  此外如果要建立一個遠端資料庫上的某張表的同義字,需要先建立一個Database Link(資料庫連接)來擴充訪問,然後在使用如下語句建立資料庫同義字:

create synonym table_name for table_name@DB_Link;

  當然,你可能需要在user使用者中給目前使用者(user2)授權: grant select/delete/update on user2

工作使用執行個體:

給目前使用者建立一同義字TBL_USERS  ,映射的表是 資料庫lsxy(一個dblink)上使用者 lisi 下的V_TBL_USERS 表。

create or replace synonym TBL_USERS  for lisi.V_TBL_USERS@ lsxy;

(2.刪除同義字:

  drop public synonym table_name;

(3.查看所有同義字:

 select * from dba_synonyms;

同義字擁有如下好處:

1、節省大量的資料庫空間,對不同使用者的操作同一張表沒有多少差別;

2、擴充的資料庫的使用範圍,能夠在不同的資料庫使用者之間實現無縫互動;

3、同義字可以建立在不同資料庫伺服器上,通過網路實現串連。

更多Oracle相關資訊見Oracle 專題頁面 http://www.bkjia.com/topicnews.aspx?tid=12

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.