Search code examples
sql-serverazuressmsazure-sql-server

In Azure SQL Server How do I Query a table in db_1 from db_2 and insert records in table in db_2


I need to identify fields in tbl_1 (2+ x 10^6 rows) in db_1 that do not match what is supposed to be the same field in tbl_2 in db_2 and insert an error log record in a tbl_3 in db_1 when a mismatch is found. Azure SQL Server does not allow me to "FROM" tbl_2 in db_2. It barfs on "db_2.dbo.tbl_2". Is this not possible in Azure SQL Server?

Error message: Msg 40515, Level 15, State 1, Line 16 Reference to database and/or server name in 'dbCaseMgmtSystemData.dbo.CM_CASE_DOCKET' is not supported in this version of SQL Server.


Solution

  • Cross-Database Queries is supported in Azure SQL. This document explains how to do that. You can query tbl_2 in db_2 and insert into tables in db_1. You need to define a stored procedure to implement your processing logic.