0

I have an empty template table called Table1. I want to copy this table multiple times so I can have Table2 Table3 Table4 and so on, including the fields.

I have tried:

SELECT *
INTO Table2
FROM Table1

but I keep getting this error:

ERROR 1327 (42000): Undeclared variable: Table2

Am I doing this wrong?

3
  • ERROR 1146 (42S02): Table 'mytables.Table2' doesn't exist Commented Jul 9, 2015 at 19:43
  • 4
    CREATE TABLE table2 AS SELECT * FROM table1; might work better for you. Commented Jul 9, 2015 at 19:45
  • possible duplicate of SELECT INTO and "Undeclared variable" error Commented Jul 9, 2015 at 19:47

2 Answers 2

1

If table doesn't exist do:

CREATE TABLE table2 LIKE table1;

After table is created do:

INSERT INTO table2 SELECT * FROM table1;
Sign up to request clarification or add additional context in comments.

1 Comment

edited to include create table syntax, if table doesn't exist
0

Since you said Table1 is empty you can create an identical empty table called Table2 like this:

create table table2 like table1

If Table1 has data in it and you want to copy the data as well, then you can do this:

create table table2 as select * from table1

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.