I’m looking to alias an object — mainly tables — in SQLServer. There is the concept of "Alias" in SQLServer, 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.
>Solution :
Yes. It’s called a synonym. eg
CREATE SYNONYM MyEmployee
FOR AdventureWorks2012.HumanResources.Employee;