SQLCriticalRuntime ErrorMay 2, 2026

Runtime Error

Cannot perform 'MERGE' operation on a non-partitioned table

What This Error Means

This error occurs when you try to perform a 'MERGE' operation on a table that does not have a partition key. The 'MERGE' statement is used to insert, update, or delete records in a table based on the records in another table.

Why It Happens

The error occurs because the table you are trying to merge data into does not have a partition key, which is required for the 'MERGE' statement. This could be because the table was created without a partition key or because the partition key was dropped.

How to Fix It

  1. 1To fix this error, you need to create a partition key on the table you are trying to merge data into. You can create a partition key using the 'CREATE TABLE' statement with the 'PARTITION BY' clause. For example:
  2. 2// Before (broken code)
  3. 3MERGE INTO customers AS target
  4. 4USING new_customers AS source
  5. 5ON target.customer_id = source.customer_id
  6. 6WHEN MATCHED THEN
  7. 7UPDATE SET target.name = source.name
  8. 8WHEN NOT MATCHED THEN
  9. 9INSERT (customer_id, name)
  10. 10VALUES (source.customer_id, source.name);
  11. 11// After (fixed code)
  12. 12CREATE TABLE customers (customer_id INT, name VARCHAR(255), PRIMARY KEY (customer_id)) PARTITION BY RANGE (customer_id);
  13. 13-- Then, you can run the MERGE statement

Example Code Solution

❌ Before (problematic code)
SQL
MERGE INTO customers AS target
USING new_customers AS source
ON target.customer_id = source.customer_id
WHEN MATCHED THEN
UPDATE SET target.name = source.name
WHEN NOT MATCHED THEN
INSERT (customer_id, name)
VALUES (source.customer_id, source.name);
✅ After (fixed code)
SQL
CREATE TABLE customers (customer_id INT, name VARCHAR(255), PRIMARY KEY (customer_id)) PARTITION BY RANGE (customer_id);

-- Then, you can run the MERGE statement
MERGE INTO customers AS target
USING new_customers AS source
ON target.customer_id = source.customer_id
WHEN MATCHED THEN
UPDATE SET target.name = source.name
WHEN NOT MATCHED THEN
INSERT (customer_id, name)
VALUES (source.customer_id, source.name);

Fix for Cannot perform 'MERGE' operation on a non-partitioned table

Related SQL Errors

Related SQL Blog Articles

Have a different error? Get an instant explanation.

Explain Another Error