Query from other database

  • I have two databases Db1 and Db2 i want to select all * from a table from db1 on the same server. I want to execute in db2 databse

  • Use

    Select * from [db1].[dbo].[tablename]

  • I would create a view on the server that your customer logs into.

    Example.

    select * from [local table name]

    union all

    select * from [remote server].[remote db name].[schema].

    This will allow you the flexability to specify columns in case the table structures are different. You can also perform joins like this.

    select a.col1, a.col2, b.col3

    from table1 a

    inner join [remote server].[remote db name].[schema].

    b

    on a.col = b.col

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply