Home > Blockchain >  Data-Object Aliases in SQL Server
Data-Object Aliases in SQL Server

Time:01-29

I'm looking to alias an object -- mainly tables -- in SQL Server. There is the concept of "Alias" in SQL Server, but this refers to at the Server/Instance level and I am looking to persistently alias db objects.

As an example:

SELECT * 
FROM [MyDB].[MySchema].[MySalesTables]

Instead being able to use:

SELECT * 
FROM sales

I know I can temporarily alias a table/field by doing:

SELECT * 
FROM [MyDB].[MySchema].[MySalesTables] AS sales

But I'm wondering if there is a management layer in SQL Server (or even SSMS) where I can just add aliases to my most common table names so that I can refer to them more easily.

CodePudding user response:

Yes. It's called a synonym. eg

CREATE SYNONYM MyEmployee   
FOR AdventureWorks2012.HumanResources.Employee;  
  •  Tags:  
  • Related