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?

Michael Morrow
  • 403
  • 2
  • 16

2 Answers2

1

If table doesn't exist do:

CREATE TABLE table2 LIKE table1;

After table is created do:

INSERT INTO table2 SELECT * FROM table1;
Fin Dev
  • 309
  • 2
  • 8
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
Ike Walker
  • 64,401
  • 14
  • 110
  • 109