Common SQL Errors

MySQL Error 1746: ER_CANT_UPDATE_TABLE_IN_CREATE_TABLE_SELECT - How to Fix and Prevent

Galaxy Team
August 7, 2025

<p>The error occurs when a statement tries to modify a table that is simultaneously being created within the same CREATE TABLE ... SELECT command or subquery.</p>

Sign up for the latest in common SQL errors from the Galaxy Team!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

What is MySQL error 1746?

<p>MySQL Error 1746: ER_CANT_UPDATE_TABLE_IN_CREATE_TABLE_SELECT happens when a query attempts to insert, update, or delete from a table that is still being built by a CREATE TABLE ... SELECT statement. Break the operation into two separate statements or use a temporary table to resolve the issue.</p>

Error Highlights

Typical Error Message

Can't update table '%s' while '%s' is being created.

Error Type

DDL Error

Language

MySQL

Symbol

ER_CANT_UPDATE_TABLE_IN_CREATE_TABLE_SELECT

Error Code

1746

SQL State

HY000

Explanation

Table of Contents

What is MySQL Error 1746 ER_CANT_UPDATE_TABLE_IN_CREATE_TABLE_SELECT?

Error 1746 appears with the message "Can't update table 'X' while 'Y' is being created." MySQL raises it when you try to read or write to a table that is the target of an ongoing CREATE TABLE ... SELECT command in the same execution context.

The server blocks concurrent updates to avoid data corruption or deadlocks while the destination table structure and data are still materializing.

What Causes This Error?

The most common cause is combining CREATE TABLE new_table SELECT ... with a subquery that references or mutates the same source table inside the SELECT clause or in a trigger.

It can also happen when triggers, stored routines, or ON DUPLICATE KEY UPDATE clauses try to alter the table being created, forcing MySQL to abort the statement for safety.

How to Fix ER_CANT_UPDATE_TABLE_IN_CREATE_TABLE_SELECT

Split the logic: first run CREATE TABLE new_table LIKE original_table, then issue a separate INSERT INTO new_table SELECT ... statement. This removes the simultaneous read-write conflict.

Alternatively, route intermediate data through a temporary table, or use CREATE TEMPORARY TABLE to avoid touching the final table until creation completes.

Common Scenarios and Solutions

ETL scripts often create an archive table with CREATE TABLE ... SELECT and immediately delete from the source. Execute the delete after the create finishes to eliminate the clash.

Reporting pipelines sometimes aggregate into a new table and join back to the source in the same statement. Replace the self-join with a temp table snapshot created beforehand.

Best Practices to Avoid This Error

Keep DDL (CREATE TABLE) and DML (INSERT/UPDATE/DELETE) in separate transactions when they involve the same objects. This sequencing removes hidden dependencies.

Enable strict testing in staging so CI/CD pipelines catch mixed DDL-DML statements before they hit production, reducing runtime failures.

Related Errors and Solutions

Error 1100: ER_TABLE_NOT_LOCKED occurs when a session tries to write without holding the proper lock. Acquiring explicit locks can fix it.

Error 1050: ER_TABLE_EXISTS_ERROR arises when a CREATE TABLE targets an existing name. Add IF NOT EXISTS or drop the table first.

Common Causes

Mixed DDL and DML in one statement

Attempting to create a table and modify it in the same SQL command.

Triggers firing on the target table

Triggers reference or update the table that is still in creation.

Stored procedures combining creation and update

A routine runs CREATE TABLE ... SELECT and then issues further DML.

ETL scripts with immediate source cleanup

Scripts delete or update source rows during the create-select operation.

Related Errors

Error 1030 ER_GET_ERRNO

Generic storage engine failure; may surface if temp tables run out of space.

Error 1100 ER_TABLE_NOT_LOCKED

Occurs when a session tries to write without the needed lock. Acquire proper locks.

Error 1050 ER_TABLE_EXISTS_ERROR

Raised when creating a table that already exists. Use IF NOT EXISTS or DROP TABLE first.

FAQs

Can I disable this safety check?

No. MySQL enforces it to protect data integrity. Instead, refactor the query.

Does the error occur in all MySQL versions?

Yes, although wording may vary. Behavior is consistent from 5.6 through 8.0.

Will temporary tables avoid the problem?

Yes. Because temp tables are session-scoped, they break the read-write dependency.

How does Galaxy help?

Galaxy flags mixed DDL-DML patterns in real time and suggests splitting statements, reducing runtime errors.

Start Querying with the Modern SQL Editor Today!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Check out some other errors

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo