Tip of the Day : Synonym Chaining

Welcome to SQL Server Helper !!!

This site is intended for those who are beginning to use SQL Server as part of their day-to-day activities.  You will find in this site a collection of useful functions, triggers, stored procedures and tips and tricks related to SQL Server.

Should you have any comments or questions regarding this site or if you want to ask SQL Server-related questions, e-mail us here.

We hope we are able to help and we are glad to help!!!

SQL Server Tip of the Day - September 27, 2016

Synonym Chaining

A synonym is a database object that servers the purpose of providing an alternative name for another database object, referred to as the base object, that can exist on a local or remote server as well as the purpose of providing a layer of abstraction that protects a client application from changes made to the name or location of the base object.

A synonym belongs to a schema, and like other objects in a schema, the name of the synonym must be unique. References to synonyms are not schema-bound. Therefore, a synonym can be dropped at any time. However, dropping a synonym runs the risk of leaving dangling references to the synonym that was dropped. These references will only be found at run time.

One restriction when creating a synonym is that a synonym cannot be the base for another synonym, otherwise the following error message is generated:

Msg 470, Level 16, State 1, Line 1
The synonym "<Synonym Name>" referenced synonym "<Synonym Name>". Synonym chaining is not allowed.

To overcome this restriction and be able create a synonym that references another synonym indirectly is with the user of a view, as can be seen from the following script:

CREATE SYNONYM [dbo].[OldStudents] FOR [SchoolArchive].[dbo].[Students]

CREATE VIEW [dbo].[OldStudents2]
SELECT * FROM [dbo].[OldStudents]

CREATE SYNONYM [dbo].[Alumni] FOR [dbo].[OldStudents2]

SELECT * FROM [dbo].[Alumni]

This work around for synonym chaining will only work if the base object used in the synonym is either a table or a view.

SQL Server 2012

SQL Server 2008

User-Defined Functions

Date Functions

A collection of useful user-defined functions that deal with dates.

String Functions

A collection of useful user-defined functions that deal with strings (varchar/char/nvarchar/nchar).

Tree Functions

A collection of useful user-defined functions that deal with tree or hierarchical design structures.

Table-Valued Functions

A collection of useful table-valued user-defined functions that can be used to join with other tables.

SQL Server Built-in Functions

A reference to all built-in functions available within SQL Server grouped into categories.

Tips and Tricks

A collection of useful SQL Server-related tips and tricks:

SQL Server Error Messages

A list of SQL Server error messages and for certain error messages, discusses ways on how to solve the error or work around them:

Frequently Asked Questions