Oracle中 SYNONYM(同義詞)的作用

官方定義

Use the CREATE SYNONYM statement to create a synonym, which is an alternative name for a table, view, sequence, procedure, stored function, package, materialized view, Java class schema object, user-defined object type, or another synonym.

Synonyms provide both data independence and location transparency. Synonyms permit applications to function without modification regardless of which user owns the table or view and regardless of which database holds the table or view. However, synonyms are not a substitute for privileges on database objects. Appropriate privileges must be granted to a user before the user can use the synonym.

翻譯:

使用該CREATE SYNONYM語句創建同義詞,這是表,視圖,序列,過程,存儲的函數,包,實例化視圖,Java類模式對象,用戶定義的對象類型或其他同義詞的替代名稱。

同義詞提供了數據獨立性和位置透明性。同義詞允許應用程序運行而無需修改,無論哪個用戶擁有該表或視圖,以及哪個數據庫擁有該表或視圖。但是,同義詞不能代替數據庫對象的特權。必須先向用戶授予適當的特權,然後用戶才能使用同義詞。

是不是不知所云???

通俗講解:

1、 多用戶協同開發中,可以屏蔽對象的名字及其持有者。如果沒有同義詞,當操作其他用戶的表時,必須通過user名.object名的形式,採用了Oracle同義詞之後就可以隱蔽掉user名。

當然這裏要注意的是:public同義詞只是爲數據庫對象定義了一個公共的別名,其他用戶能否通過這個別名訪問這個數據庫對象,還要看是否已經爲這個用戶授權。

2、爲用戶簡化sql語句。上面的一條其實就是一種簡化sql的體現,同時如果自己建的表的名字很長,可以爲這個表創建一個Oracle同義詞來簡化sql開發。

3、爲分佈式數據庫的遠程對象提供位置透明性。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章