Monday, March 13, 2006

SQL 2005 - SYNONYMS

Remember how uneasy it was to write multiple queries which had four part object names
(ServerName.DatabaseName.OwnerName.ObjectName). Using SYNONYMS (new in SQL Server 2005) you can create an alias for objects.

Example:
-- Without SYNONYMS you would use the query the following way:
Select * from LongServerName.LongDatabaseName.LongOwnerName.LongObjectName
-- With SYNONYMS CREATE SYNONYM LNG FOR LongServerName.LongDatabaseName.LongOwnerName.LongObjectName
-- Once you create the SYNONYM you can use the above query as follows
Select * from LNG

No comments: