How do I create and use a Synonym for a table in SQL Server 2005?

June 14, 2008 at 1:06 am Leave a comment

To create a synonym, run the following SQL code:

USE AdventureWorks;
GO
CREATE SYNONYM MyLocation
FOR AdventureWorks.Production.Location;
GO

To use the synonym, run the following SQL code:

USE AdventureWorks;
GO
SELECT TOP 5 * FROM MyLocation;
GO

To drop the synonym, run the following SQL code:

USE AdventureWorks;
GO
DROP SYNONYM MyLocation;
GO

Advertisements

Entry filed under: SQL Scripts. Tags: , , , , , .

How do I list all tables WITHOUT a primary key? How do I check if a SQL Server 2005 installation has been Service Packed?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


Calendar

June 2008
M T W T F S S
    Jul »
 1
2345678
9101112131415
16171819202122
23242526272829
30  

Archives

Blog Stats

  • 32,523 hits

%d bloggers like this: