Instances of synonyms in SQL SERVER 2005

Source: Internet
Author: User

In SQL SERVER 2005, a synonym has finally appeared, which makes it much easier to use. Here's a small example to illustrate

Synonyms are database objects that are used to achieve the following purposes:

Provides alternate names for another database object (called a "base Object") on a local or remote server.

Provides an extract layer that prevents the name or location of the base object of the client application from being changed.

For example, the employee table for Adventure Works is on a server named Server1. To refer to this table from another server Server2, the client application must use a four-part name Server1.AdventureWorks.Person.Employee. Also, if you change the location of the table (for example, to another server), you need to modify the client application to reflect the changes. Some features have been summed up in http://www.cnblogs.com/jackyrong/archive/2006/06/15/426304.html, and examples are given here, examples from foreigners.
Set up two databases first
Create Database Riverresearch
Go
Use Riverresearch
Go

Then set up the schema and table for two databases, and the stored procedures are as follows

Use rainbowresearchgocreate schema raingocreate schema snowgocreate table Rainbowresearch.Rain.Cities (ID int., City varch  AR (+)) Goinsert into Rainbowresearch.Rain.Cities Select 1, ' Hongkong ' inserts into Rainbowresearch.Rain.Cities select 2, ' Tokyo ' INSERT into Rainbowresearch.Rain.Cities select 3, ' Beijing ' insert into Rainbowresearch.Rain.Cities Select 4, ' Ta Ipei ' INSERT into Rainbowresearch.Rain.Cities Select 5, ' Seoul ' insert into Rainbowresearch.Rain.Cities Select 6, ' Mumbai ' Gocreate procedure rain.displaycities @id intasselect city from Rainbowresearch.Rain.Cities where [email protected ]gocreate table Rainbowresearch.Snow.Cities (id int, city varchar) Goinsert to Rainbowresearch.Snow.Cities Select 1, ' Tokyo ' insert into Rainbowresearch.Snow.Cities select 2, ' Seoul ' insert into Rainbowresearch.Snow.Cities select 3, ' Mo Scow ' INSERT into Rainbowresearch.Snow.Cities Select 4, ' NewYork ' gocreate procedure snow.displaycities @id intasselect Ci Ty from Rainbowresearch.Snow.CiTies where [email protected]gouse riverresearchgocreate Schema rivergogocreate table RiverResearch.River.Cities ( ID int, city varchar (goinsert) to RiverResearch.River.Cities Select 1, ' Hongkong ' insert into RIVERRESEARCH.RIVER.C  Ities Select 2, ' Tokyo ' insert into RiverResearch.River.Cities select 3, ' Beijing ' insert into RiverResearch.River.Cities Select 4, ' Taipei ' insert into RiverResearch.River.Cities Select 5, ' Seoul ' gocreate procedure river.displaycities @id int  Asselect City from RiverResearch.River.Cities where[email protected]Go
Here, in the Rainbowresearch database set up two patterns, Rain,snow, and then set up in these two modes of the city table, and in
Riversearch database also established a model river, also set up a table cities, so simple, not detailed description.
After that, we query the content that was just built.
SELECT * FROM RiverResearch.River.Citiesgoselect * from Rainbowresearch.Rain.Citiesgoselect * FROM Rainbowresearch.Snow.Citiesgo
Finally, we create synonyms
Use rainbowresearchgocreate synonym  rivercities for RiverResearch.River.Citiesgocreate synonym  raincities For Rainbowresearch.Rain.Citiesgocreate synonym  snowcities for Rainbowresearch.Snow.Citiesgouse Riverresearchgocreate synonym  rivercities for RiverResearch.River.Citiesgocreate synonym  raincities for Rainbowresearch.Rain.Citiesgocreate synonym  snowcities for Rainbowresearch.Snow.Citiesgo
You see, it's a lot easier.
Check again, it's a lot easier this time.
Use Riverresearchgoselect * from Rivercitiesselect * from Raincitiesselect * from Snowcitiesgouse rainbowresearchgoselect * FROM Rivercitiesgoselect * from Raincitiesgoselect * from Snowcitiesgo
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.