Synonym is an alternate name given to an object.
Create synonym < synonym_name> for < table_name>;
Create synonym e1 for EMP;
From now, to access table EMP, we can use the synonym e1
Select * from e1;
Insert into e1 (empno, ename, Sal, deptno) values ( 444,’AAA’, 2000, 10);
We can use synonyms not only for select stmt, for DML commands also.
What is the advantage of creating synonym?
Generally, table name will be long.
Instead of using lengthy tables names in the SQL queries, we can use synonyms.
What is difference between table aliases and synonyms?
Do you remember, we have learnt table alias concept in joins, which helps in reducing the length of the query.
Table alias is temporary, where as synonym are permanent.
Query to see list of synonyms:
Select synonym_name from user_synonyms;
When you do not want synonym, we can drop it.
Drop synonym < synonym_name>;
Drop synonym e1;