Reputation: 2146
I am a MSSQL user and now I am converting my database to MySQL. I am writing the following query in MySQL:
SELECT * INTO new_tbl FROM tbl;
And I get the following error
Error : Undeclared variable new_tbl
How such a query should be properly written in MySQL?
Upvotes: 108
Views: 187034
Reputation: 1995
Use the CREATE TABLE SELECT syntax.
http://dev.mysql.com/doc/refman/5.0/en/create-table-select.html
CREATE TABLE new_tbl SELECT * FROM orig_tbl;
Upvotes: 168
Reputation: 8664
In MySQL, It should be like this
INSERT INTO this_table_archive (col1, col2, ..., coln)
SELECT col1, col2, ..., coln
FROM this_table
WHERE entry_date < '2011-01-01 00:00:00';
Upvotes: 106