Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2006
    Posts
    2

    Post Unanswered: 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.

  2. #2
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    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]
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  3. #3
    Join Date
    Jun 2006
    Posts
    2
    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

  4. #4
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    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:
    Code:
    Use Database1
    go
    
    select	Table1.Column1,
    	Table2.Column2	
    from	Table1
    	inner join Database2.dbo.Table2 as Table2 on Table1.pkey = Table2.pkey
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •