Synonym in Oracle
Ques. ==> Difference between synonym and alias?
Ans. ==> Synonyms is permanent alternative for any database object. You can access that database object with that alternative until you drop that synonym but in case of alias it is temporary name used only in query to point any database object by writing alias name after database object name.
Consider example of using alias.
==>Selecting client table
==>Selecting client table using alias
==>Selecting client table using alias only
Now we will see syntax of synonym and it’s example
Syntax for creating synonym
CREATE SYNONYM synonym_name
FOR object_name;
Example –
Create Synonym C
for client;
Now selecting client table
Select * From client;
Now selecting client table using synonym
Select * From C;
Now inserting data in client table using synonym
Insert into C values (6,’ramesh’);
Now selecting client table
Select * From client;
NOTE :- Now it is clear that all commands on database objects can be performed using synonym but this cannot be in case of alias.
Syntax for Destroying a Synonym
Drop synonym synonym_name;
Drop synonym C;
Now selecting client using synonym will display error as shown below.
Select * From C;
But client table remain as it is with it’s data.
Select * From client;
I hope this article will help you.