query with join across multiple databases-syntax error

后端 未结 3 1808
醉酒成梦
醉酒成梦 2021-01-25 19:45

I have 2 databases namely db1,db2. I need a query that fetch the data from these dbs(db1,db2) which have inturn 2 tables(concessions,invoicing) each.

In db1.concessions

3条回答
  •  情深已故
    2021-01-25 20:27

    If the databases are on the same SQL Server instance you can use 3 part naming:

    database_name.schema_name.object_name
    

    Using Identifiers As Object Names

    If the databases are not on the same instance, create a linked server: Linked Servers

    Creating Linked Servers (SQL Server Database Engine)

    A linked server allows for access to distributed, heterogeneous queries against OLE DB data sources. After a linked server is created, distributed queries can be run against this server, and queries can join tables from more than one data source. If the linked server is defined as an instance of SQL Server, remote stored procedures can be executed.

提交回复
热议问题