Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 2 server used in 1 query

Author  Topic 

Villanuev
Constraint Violating Yak Guru

478 Posts

Posted - 2012-05-23 : 23:24:43
Hi Forumer’s

I would like to create an script that will use 2 server. The first table tableA is stored in server1 and tableB stored in sever2. Is this possible? what are the requirements. Kindly please help me guys on how to do this.


thanks in advance.


jov

yosiasz
Master Smack Fu Yak Hacker

1635 Posts

Posted - 2012-05-23 : 23:46:01
yes it is possible

1. Use ssis or
2. use linked servers

These are the options that I know of

<><><><><><><><><><><><><><><><><>
If you don't have the passion to help people, you have no passion
Go to Top of Page

mani_12345
Starting Member

35 Posts

Posted - 2012-05-24 : 00:04:41
heii...
I am not sure about this but i guess the solution for this prbm will be :

for this you have to create one field in Server1 table that points to the server2 i.e Server2 name and then try to get information ..
Just thought for this have not tried yet...

Go to Top of Page

Villanuev
Constraint Violating Yak Guru

478 Posts

Posted - 2012-05-24 : 03:55:57
Thank you guys for the reply.

@yosiasz
I think the option #2,
But how could i do this?

sample: I have to get some information from table2 under server2 using the table1 under server1.

SERVERNAME: SERVER1
DBNAME: SAMPLEDB1
TABLE: TABLE1
--------------------
SERVERNAME: SERVER2
DBNAME: SAMPLEDB2
TABLE: TABLE2




Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-05-24 : 16:01:43
quote:
Originally posted by Villanuev

Thank you guys for the reply.

@yosiasz
I think the option #2,
But how could i do this?

sample: I have to get some information from table2 under server2 using the table1 under server1.

SERVERNAME: SERVER1
DBNAME: SAMPLEDB1
TABLE: TABLE1
--------------------
SERVERNAME: SERVER2
DBNAME: SAMPLEDB2
TABLE: TABLE2







see how to add a linked server here

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=164892

once this is then the you can simply use a query like below
(assuming linked server is created in SERVER1 for SERVER2)


USE [SAMPLEDB1]
GO

SELECT *
FROM dbo.TABLE1 t1
INNER JOIN [SERVER2].[SAMPLEDB2],[dbo].TABLE2
ON...


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Villanuev
Constraint Violating Yak Guru

478 Posts

Posted - 2012-05-24 : 21:28:53

Hi Visakh, Thank you very much for this very informative info.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-05-25 : 10:10:09
you're welcome

courtesy: Kristen

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -