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?
MySQL Server doesn't support the SELECT ... INTO TABLE Sybase SQL extension. Instead, MySQL Server supports the INSERT INTO ... SELECT standard SQL syntax, which is basically the same thing.
The SELECT INTO command copies data from one table and inserts it into a new table. The following SQL statement creates a backup copy of Customers: SELECT * INTO CustomersBackup2017.
The SELECT INTO statement is a query that allows you to create a new table and populate it with the result set of a SELECT statement . To add data to an existing table, see the INSERT INTO statement instead. SELECT INTO can be used when you are combining data from several tables or views into a new table.
Introduction to SQL Server SELECT INTO statement The SELECT INTO statement creates a new table and inserts rows from the query into it. If you want to copy the partial data from the source table, you use the WHERE clause to specify which rows to copy.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With