Showing posts with label SQL Synonym. Show all posts
Showing posts with label SQL Synonym. Show all posts

SQL Synonym

Synonym

Synonym:-A synonym is an alias for a table, view, snapshot, sequence, procedure, function,
or package.

There are two types to SYNONYMS they are
1) PRIVATE SYNONYM :-This can be access only who created .
2) PUBLIC SYNONYM :-This can be access by any user.

Syntax for Private SYNONYMS:-

Create or replace synonym for ;

Syntax for Public SYNONYMS:-

Create or replace public synonym for ;

CREATE SYNONYMS:-
Example:- Below is the private synonym

SQL>create or replace synonym employee for emp;

Data selection from private synonym:-

SQL>select * from employee;

Example:- Below is the public synonym
SQL>create or replace public synonym employee1 for emp;--Public

Data selection from public synonym:-

SQL>select * from employee1;

Note:- Only public synonym can be access by any user but private synonym can be accessed by creator.

Dropping Synonyms:-

SQL>drop synonym employee;  --drop private synonym
SQL>drop public synonym employee1;  --drop public synonym

Listing information about synonyms:-
SQL>select * from user_synonyms;