Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Data-Object Aliases in SQL Server

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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;  
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading