Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I select a SQL server?

Tags:

sql

sql-server

The company I work for uses a bunch of different SQL servers and I was wondering how to select a different SQL server in the same script.

For example, I want to select data from a table on a database in server 1 and using that data to get data from another table on a database in server 2. I tried googling the solution but I couldn't find anything relevant to my problem.

Thanks in advance.

like image 898
user558594 Avatar asked Jul 13 '26 05:07

user558594


2 Answers

You can set them up as linked servers.

http://msdn.microsoft.com/en-us/library/aa560998(v=bts.10).aspx

then you syntax will be

SERVERALIAS.DBNAME.owner.TABLE
like image 78
turtlepick Avatar answered Jul 14 '26 18:07

turtlepick


Use fully qualified names (i.e. select * from [server].[database].[owner].[tablename])

Also, be sure to setup those servers as linked servers. There are several articles online how to do this.

like image 43
Kyle B. Avatar answered Jul 14 '26 19:07

Kyle B.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!