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
 General SQL Server Forums
 New to SQL Server Programming
 Other Server and Database Connection

Author  Topic 

rpc86
Posting Yak Master

200 Posts

Posted - 2008-08-21 : 20:17:46
Hi guys,

How will I connect to other Server Name and Database name ?

Say I'm in SQL Query and my current server is (Local), and my database is myDB. How will I connect to (Server_01) and to open a Database from it?

Thank you

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-08-21 : 20:20:18
Register another server in the client tool or use a linked server.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

rpc86
Posting Yak Master

200 Posts

Posted - 2008-08-21 : 20:22:32
I already have 2 servers. How to use a linked server?

thank you
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-08-21 : 20:27:09
Once you've setup the linked server, you can then use the four-part naming convention to get to the remote server:

LinkedServerName.DatabaseName.ObjectOwner.ObjectName

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

rpc86
Posting Yak Master

200 Posts

Posted - 2008-08-21 : 20:30:35
Ok. I tried this one. Under my local development machine, there are 2 databases DB1 and DB2. How will I switch to other database on the same server name ?

I changed my questions because its hard for me to cope that.

Thanks.
Go to Top of Page

ratheeshknair
Posting Yak Master

129 Posts

Posted - 2008-08-22 : 04:39:49
Usethe command USE DB_name to switch between databases.If u are in DB1 and want to access table from DB2 then
select * from DB2.schema_name.table_name

RKNAIR
Go to Top of Page
   

- Advertisement -