What is (Private) Synonym?

The web gives me a definition of Synonym as "A word that means the same as another word." Well Oracle also defines its Synonyms in the same way. Then what is a Private Synonym? It is nothing more than a Synonym accessible to users of the particular schema where the synonym is created. Public synonyms on the other hand once created by any user, will be accessible for all schemas in a particular database.

How to create a (Private) Synonym?
The syntax for creating a synonym is

CREATE [ OR REPLACE ] SYNONYM synonym_name FOR object;

Example:

CREATE SYNONYM clerk FOR employee;

In our context employee is a table (or can be a view). As Clerk is also an employee, it makes understanding more easy.

You can query from clerk as you would do from employee table/view. Now you must have got the idea of why a synonym is used. 

Note: The usage of a (private) synonym from public synonym will be where you need to expose your not-so critical data to all database users. If your data is considered private, you should be creating private synonyms for this purpose.

How to destroy a Synonym?
To destroy or drop a synonym follow the syntax:

DROP SYNONYM synonym_name;

Example:

DROP SYNONYM clerk;


Click here to learn What is Public Synonym

No comments :

Post a Comment