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:

Object Explorer

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.

Similar Reads

Usage of the SYNONYNM

Step 1: Create the database Geeksforgeeks by using the following SQL query...

How to Create a Synonym for Table CoursesActive.

Query...

How to Create a Synonym for Table Along with its schemaName.

Step 1: Create a database GeeksforGeeksSchool...

How to Updates the Base Table After Adding a Row

Query...

How to Create a Synonym for a Stored Procedure in an SQL Server

Step 1: Create a stored procedure to find the most sold course....

Deleting a Synonym

We can’t create a duplicate or ALTER the synonym, to alter the synonym the current synonym should be dropped and then it can be recreated....

How to DELETE a Synonym and Access it After the Deletion.

Query...

How to Check Already Existing Synonyms.

Method 1: Using the Query...

Where to Use Synonyms

In a scenario where we have lengthy names and want to keep an alias with a short name. It enhances security since it helps hide the schema details. In case we want to avoid hardcoding by using different development environments To enable dynamic schema and server changes, the synonym pointing will change when the schema is changed. To enhance the readability by providing meaningful synonyms....

Advantages of Using Synonym

Synonyms reduce the efforts by helping us keep the length reduced alias All the changes made in the base table will be reflected here and the changes made in the synonym also change in the base table Creates and abstraction the base table....

Drawbacks

When the base table gets renamed the old synonyms get invalid and become dangling synonyms so whenever a renaming or new table is created then the respective synonyms should be made....

Conclusion

Synonyms in SQL Server act as a alias for the databbase objects and give straightforward naming convention. It allow developer to give simple or easy name to the database or tables for its simplicity. Overall, it make database more adaptable....