views:

634

answers:

3

What is the use of SYNONYM in SQL Server 2008?

+2  A: 

MSDN has a good explanation here: http://msdn.microsoft.com/en-us/library/ms177544.aspx

jamesaharvey
This is a horrible answer. Posting only a link is not what this site is about. I advise you start by reading the FAQ.
Geoffrey Chetwood
Nevermind that I had already posted the same link, to boot. Though I wouldn't define this answer 'horrible'. At least, it's correct.
Adriano Varoli Piazza
+1, sometimes you cannot write an answer as complete or as well as the linked article. what is the difference if you read it on SO or a linked page?
KM
@KM: The difference might be thatyou don't get a bored geek like Rich B nagging at you.
Adriano Varoli Piazza
This was a simple question, that I gave a simple answer to. I've read the FAQ and don't see anything objecting to posting a link to a definitive reference, although there is a section titled 'Be nice.' that you might want to take a look at again, Rich.
jamesaharvey
+2  A: 

Seems (from here) to create an alias for another table, so that you can refer to it easily. Like as select * from table longname as ln but permanent and pervasive.

Edit: works for user-defined functions, local and remote objects, not only tables.

Adriano Varoli Piazza
+1  A: 

An example of the usefulness of this might be if you had a stored procedure on a Users database that needed to access a Clients table on another production server. Assuming you created the stored procedure in the database Users, you might want to set up a synonym such as the following: USE Users; GO CREATE SYNONYM Clients FOR Offsite01.Production.dbo.Clients; GO

Now when writing the stored procedure instead of having to write out that entire alias every time you accessed the table you can just use the alias Clients. Furthermore, if you ever change the location or the name of the production database location all you need to do is modify one synonym instead of having to modify all of the stored procedures which reference the old server.

From: http://blog.sqlauthority.com/2008/01/07/sql-server-2005-introduction-and-explanation-to-synonym-helpful-t-sql-feature-for-developer/

thomas

related questions