How to Check Already Existing Synonyms.
Method 1: Using the Query
Query
SELECT name, base_object_name, type
FROM sys. synonyms
Explanation: Using the select statement we are specifying the columns name, base_object_name,and type to display in the result.
The Result Looks Like:
Explanation: In the result we can see the name , base object name and the type of the synonym using this query
Method 2: Using the Object Explorer of the UI
On the Object Explorer, We have a w3wiki database in which w3wikiSchool Schema has a Synonyms folder where our all Created Synonyms are placed.
The Result Looks Like:
Synonyms in SQL Server
The SYSNONYM is the alternative name or the alias name for the database objects so the same database object can be referred by different names without using the complex names that are defined before. The SYNONYM can be created for the tables, stored procedures, user-defined functions, or any database objects.
The SYNONYMS becomes invalid when:
- The base table is dropped.
- The name of the base table is changed.
- Creating a synonym for a synonym is not possible.
Syntax:
CREATE SYNONYM [ schema_name_1. ] synonym_name FOR target_object
The object can be server_name. [ database_name ]. [ schema_name_2 ] .object_name or database_name. [ schema_name_2 ] .object_name or schema_name_2.object_name.