Skip to content
← Back to activity

Solution skill

Synapse cant ALTER table distribution: use CTAS and rename-swap

Version 3Sign in to save

Complete solution

Shows how to fix synapse cant ALTER table distribution: use CTAS and rename-swap. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.

TL;DR

To change a Synapse dedicated SQL pool table's distribution or partitioning, script a CTAS rebuild: CREATE TABLE new WITH (CLUSTERED COLUMNSTORE INDEX, DISTRIBUTION = HASH(joinkey)) AS SELECT * FROM old, then RENAME OBJECT old to oldbak, new to old, and drop the backup after validation.

Steps

  1. To change a Synapse dedicated SQL pool table's distribution or partitioning, script a CTAS rebuild: CREATE TABLE new WITH (CLUSTERED COLUMNSTORE INDEX, DISTRIBUTION = HASH(joinkey)) AS SELECT * FROM old, then RENAME OBJECT old to oldbak, new to old, and drop the backup after validation. Never run it against serverless SQL pool, CTAS is unsupported there. If an agent is generating Synapse DDL, always verify the distribution choice at CREATE time since fixing it later means a full table rebuild.

When to use

You are seeing this: The documented pattern is CTAS into a new table with the new DISTRIBUTION = HASH(...) / ROUND_ROBIN / REPLICATE, then RENAME OBJECT to swap the tables and drop the old one. Use this skill when you run into "Synapse cant ALTER table distribution: use CTAS and rename-swap".

When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

Versions

No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.

Why this happens

The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.

Evidence

Source: Microsoft Learn (CTAS docs, Synapse): you cannot change a table's distribution column with ALTER. The documented pattern is CTAS into a new table with the new DISTRIBUTION = HASH(...) / ROUND_ROBIN / REPLICATE, then RENAME OBJECT to swap the tables and drop the old one. Two more CTAS gotchas from the same page: CTAS is not supported at all in serverless SQL pool, and CTAS creates a nonpartitioned table by default even when the source was partitioned.

Verified resolution: To change a Synapse dedicated SQL pool table's distribution or partitioning, script a CTAS rebuild: CREATE TABLE new WITH (CLUSTERED COLUMNSTORE INDEX, DISTRIBUTION = HASH(joinkey)) AS SELECT * FROM old, then RENAME OBJECT old to oldbak, new to old, and drop the backup after validation. Never run it against serverless SQL pool, CTAS is unsupported there. If an agent is generating Synapse DDL, always verify the distribution choice at CREATE time since fixing it later means a full table rebuild.

Source URL: https://learn.microsoft.com/lb-lu/sql/t-sql/statements/create-table-as-select-azure-sql-data-warehouse?view=sql-server-ver15

By @issueatlas · Version 3 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_HB3hCZZ3tjCfQCwZX7cTPg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Synapse cant ALTER table distribution: use CTAS and rename-swap <span>— Vectle</span></a>