Friday, March 23, 2012

How to make a select to another database using sp_addlinkedserver?

Hi all,
I trying to use sp_addlinkedserver, after I added successfully a new linked
server I do not know how to use the server...
I did this to add the server:
exec sp_addlinkedserver
'Server2','sqloledb','Northwind','myComp
uter','','','Region'
Now, I want to do a simple SELECT statement to the Region table of
Northwind, how do I do this?
Obviously, I am in another database...like for example "pubs"
Thanks for help,
Marcelo Moreiraselect * from linkedservername.database.owner.table
Regards
--
Mike Epprecht, Microsoft SQL Server MVP
Zurich, Switzerland
IM: mike@.epprecht.net
MVP Program: http://www.microsoft.com/mvp
Blog: http://www.msmvps.com/epprecht/
"Marcelo Moreira" <marcelo.moreira@.vpconsulting.pt> wrote in message
news:e6LaETghFHA.2484@.TK2MSFTNGP15.phx.gbl...
> Hi all,
> I trying to use sp_addlinkedserver, after I added successfully a new
> linked server I do not know how to use the server...
> I did this to add the server:
> exec sp_addlinkedserver
> 'Server2','sqloledb','Northwind','myComp
uter','','','Region'
> Now, I want to do a simple SELECT statement to the Region table of
> Northwind, how do I do this?
> Obviously, I am in another database...like for example "pubs"
> Thanks for help,
> Marcelo Moreira
>|||Hi,
In Link server you could also use OPEN QUERY to query the databases
Open Query
Select * from openquery('<Linked Server>','select * from
DBNAME.Table_owner.Table_Name')
Thanks
Hari
SQL Server MVP
"Marcelo Moreira" <marcelo.moreira@.vpconsulting.pt> wrote in message
news:e6LaETghFHA.2484@.TK2MSFTNGP15.phx.gbl...
> Hi all,
> I trying to use sp_addlinkedserver, after I added successfully a new
> linked server I do not know how to use the server...
> I did this to add the server:
> exec sp_addlinkedserver
> 'Server2','sqloledb','Northwind','myComp
uter','','','Region'
> Now, I want to do a simple SELECT statement to the Region table of
> Northwind, how do I do this?
> Obviously, I am in another database...like for example "pubs"
> Thanks for help,
> Marcelo Moreira
>sql

No comments:

Post a Comment