SQL Tran Docs
  • Overview
    • About
    • Getting started
    • Object lifecycle
    • Why is there no AI inside?
    • Performance considerations
    • Security considerations
    • Assessment
    • Unlocking projects
    • Interface walk-through
    • Translation scenarios
    • Prerequisites for Azure Marketplace deployment
  • Emulation scenarios
    • Emulation in SQL Tran
    • SQL Server to Fabric Warehouse
      • Data types
      • Case sensitivity
      • Cursors
        • Basic cursor loop
        • Cursor types
        • Fetch direction modes
        • Cursors in control flow
        • Nested cursors
        • Data modification cursors
        • Multiple cursors
        • Subqueries and filtering
      • Named procedure parameters
      • Result set limiting
      • MERGE statements
      • Computed columns
      • Temporary tables
      • External tables
      • Identity columns
      • Default values
      • Sequences
      • Unsupported system features
    • Synapse Analytics to Fabric Warehouse
      • Data types
      • Case sensitivity
      • Named procedure parameters
      • Result set limiting
      • MERGE statements
      • Temporary tables
      • External tables
      • Identity columns
      • Default values
      • Materialized views
      • Create table as select (CTAS)
      • Unsupported system features
    • SQL Server to Synapse Analytics
    • Oracle to PostgreSQL
  • Project wizard
    • Source database
    • Target database
    • Wrapping up
  • Projects
    • Project list
    • Overview
    • Workspace
    • Reports
    • Tests
    • Scratch pad
    • Settings
      • Project name
      • Mapping
      • Database connections
    • Navigation
    • Object complexity
    • Static analysis
    • Translation errors
    • Exporting and importing projects
  • Workspace
    • Object tree
    • Data lineage
    • Code
    • Actions
      • Overriding source
      • Overriding target
      • Ignoring objects
  • Tests
    • Workflow
    • Configure SQL Tran
    • Connecting to databases
      • Fabric Warehouse
      • Synapse Dedicated SQL Pool
      • Azure SQL Database, Azure SQL Managed Instance, Microsoft SQL Server
    • Tables
    • Views
    • Procedures
    • Functions
    • Triggers
    • Performance tests
  • Scripter
    • About
    • Supported databases
    • SQL Server
    • Azure SQL
    • Synapse Dedicated Pool
    • Oracle
    • PostgreSQL
    • MySQL
  • Microsoft training - SQL Tran
    • Introduction
    • Licensing plans
    • Deploying and activating
    • Creating a new project
    • Exploring the Overview screen
    • Inside the Workspace screen
    • Code translation and emulations
      • Data type emulation
      • Case sensitivity emulation
      • Named parameters emulation
      • Result set limiting emulation
      • Merge statements emulation
      • Identity column emulation
      • Default values emulation
      • Detection of unsupported features
Powered by GitBook
On this page
  • Code example
  • Training video example
  1. Microsoft training - SQL Tran
  2. Code translation and emulations

Merge statements emulation

PreviousResult set limiting emulationNextIdentity column emulation

Last updated 8 hours ago

In Synapse Analytics, the MERGE statement allows conditional INSERT, UPDATE, and DELETE operations to be performed in a single declarative block, simplifying synchronization and deduplication logic.

However, Microsoft Fabric Warehouse does not support MERGE, requiring developers to manually rewrite complex operations as separate queries — a process that can be time-consuming and error-prone.

SQL Tran automatically handles this incompatibility by splitting a MERGE block into individual UPDATE, INSERT, and DELETE statements that preserve the original intent. It rewrites each condition into a standalone operation, ensuring that the logical flow and data integrity are maintained.

This emulation eliminates the need for manual rewrites, simplifying the migration of complex ETL and data warehousing processes.

(For more information, see the following emulation reference page: )


Code example

Synapse Analytics:

MERGE INTO TargetTable AS t
USING SourceTable AS s
ON t.ID = s.ID
WHEN MATCHED THEN
    UPDATE SET t.Name = s.Name
WHEN NOT MATCHED THEN
    INSERT (ID, Name)
    VALUES (s.ID, s.Name)
WHEN NOT MATCHED BY SOURCE THEN
    DELETE;

Fabric Warehouse (generated by SQL Tran):

DELETE FROM t
FROM
	TargetTable AS t
WHERE
	NOT EXISTS (SELECT 1
	FROM
		SourceTable AS s
	WHERE
		t.ID = s.ID);
UPDATE t SET
	t.Name = s.Name
FROM
	TargetTable AS t
	INNER JOIN SourceTable AS s ON t.ID = s.ID;
INSERT
	INTO TargetTable (ID, Name)
	SELECT s.ID,
		s.Name
	FROM
		SourceTable AS s
	WHERE
		NOT EXISTS (SELECT 1
		FROM
			TargetTable AS t
		WHERE
			t.ID = s.ID);

Training video example

In the example shown, a procedure contains a MERGE statement that synchronizes data based on matching conditions between source and target tables.

Since Fabric does not support MERGE, SQL Tran automatically translates the logic by generating separate UPDATE, INSERT, and DELETE statements in the target SQL.

Each part of the original MERGE is accurately emulated through deterministic operations, preserving both the correctness and intent of the original logic.

This preserves the original intent and ensures the code behaves consistently in Fabric’s environment, even without native MERGE support.

MERGE statements
MERGE statement emulation in translated SQL