Friday, 15 May 2026

Can a synonym reference another synonym

SQL Server does not allow synonym chaining, meaning a synonym cannot reference another synonym, to avoid recursive resolution, runtime complexity, and hidden dependency issues. Each synonym must point directly to a base object. A synonym cannot reference another synonym.

This is called synonym chaining, and SQL Server explicitly blocks it.

Let’s see the demo

Creating a table and inserting few data

CREATE TABLE dbo.Products

(

    ProductID INT PRIMARY KEY,

    ProductName VARCHAR(50)

); 

INSERT INTO dbo.Products VALUES (1,'Laptop'),(2,'Mouse');

 

 Creating a synonym

CREATE SYNONYM dbo.ProductSyn1 FOR dbo.Products;

Creating another synonym using first one.

CREATE SYNONYM dbo.ProductSyn2 FOR dbo.ProductSyn1;

Synonyms created successfully.

Let’s run this

Ooo! Getting an error.

So we cannot referrer one synonym to another one.

No comments:

Post a Comment

If you have any doubt, please let me know.

Popular Posts