Wednesday, March 28, 2012

How to connect two databases on alocal server in SQL

Hello , This is Vidya newly joined to this group.
I want some help .... Its really urgent

In my project I want to connect to two databases on alocal server in SQL ? Is there any SQL query to connect two databases ?

Situation is=>
There are two Databases Db1, Db2. I want to take data from tables of Db1 to data of tables of Db2 and vice versa.I want simple SQL query without any scripting language or VB statements. Its very urgent Please help me in that.If the two databases are on the same server you can reference either one in the other by using the fully qualified object name: [database].[owner].[object]|||Thank You Sir, For your quiock reply. I have tried it but still I am unable to connect.

Sir can we have '-' (Hyphen Character) for our database name? like a_com_-_b, Is It a valid name...

Thank You|||Yes, database names can contain hyphens. But I would not recommend it for reasons of style.

Post the code you are trying that is not working. You should be able to do something like:
Use Database1
go

select Table1.Column1,
Table2.Column2
from Table1
inner join Database2.dbo.Table2 as Table2 on Table1.pkey = Table2.pkey

No comments:

Post a Comment