create Verified current stable Not installed? Data Processing

Create / Create Table From Another Definition

Create Table From Another Definition

Creates a new table based on another table's schema without data.

$
Terminal
create table <table_name> like <another_table>;

When To Use

When replicating table structure for alterations without data migration.

Pro Tip

Consider using storage engines to match the source table for consistency in performance characteristics.

Command Builder

Tune the command before you copy it

Back to syntax
$
Generated Command
create table <table_name> like <another_table>;

Anatomy of Output

Understanding the result

Query OK, 0 rows affected (0.03 sec) Execution Status

Indicates operation completed without issues.

CREATE TABLE `new_table_name` LIKE `source_table_name`; Executed Command

Outputs the command that was run.

Troubleshooting

Common pitfalls

ERROR 1050 (42S01): Table 'new_table_name' already exists

Solution: Use a different name or drop the existing table.

ERROR 1146 (42S02): Table 'xyz.source_table_name' doesn't exist

Solution: Verify the source table exists prior to cloning.

ERROR 1049 (42000): Unknown database 'xyz'

Solution: Check if the database is specified correctly in the context.

Command Breakdown

What each part is doing

create
Base Command
The executable that performs this operation. Here it runs Create before the shell applies any redirect operators.
<table_name>
table name
The value supplied for table name.
<another_table>
another table
The value supplied for another table.

Alternative Approaches

Comparable commands in other tools

Alternative data processing tools for the same job.