In this article, we learn about the SQL Server synonym.
- A synonym is an alias to the table, view, sequence, stored procedure, and function.
There are two types of synonym:
- Private synonym:- A private synonym exists only in a specified user. The owner controls the availability of synonym to the user.
- Public synonym:- A public synonym available to all users in the database.
SYNTAX OF CREATING SYNONYM
CREATE SYNONYM <synonym_name > FOR <object name>
Example:- CREATE SYNONYM orders1 FOR orders
SYNTAX OF DROPPING SYNONYM
DROP SYNONYM <synonym_name >
Example:- DROP SYNONYM orders1
- The sys.synonyms contains an entry of synonyms in a database.
- The below statement retrieves the synonym in the database.
SELECT * FROM sys.synonyms
If you are a newbie to database learning — SQL Server recommended is the following must-watch video: -