2012-02-15 20 views
2

我正在運行SQL服務器,需要使用SELECT ... INTO命令運行一些命令。目前(作爲測試)我運行這個命令:SQL SELECT ... INTO簡介 - 爲什麼它不會運行?

SELECT * 
INTO `assets_copy` 
FROM `assets` 

最簡單的例子可能的,但它仍然會無法運行。我得到的錯誤:

MySQL said: 

#1064 - You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'assets_copy` FROM `assets` LIMIT 0, 30' at line 1 

所以我想知道如果我使用的SQL版本不支持這個?我正在使用MySQL的3.23.49。

+1

可能重複[MySQL的(5.1.35):SELECT INTO不工作(http://stackoverflow.com/questions/1189810/mysql-5-1-35 - 選入不工作) – 2012-02-15 04:11:35

回答

6

Based on the documentation,MySQL不支持SELECT INTO語法。相反,你必須使用

INSERT INTO assets_copy 
    SELECT * FROM assets; 

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.

+0

非常感謝!這有很大的幫助,儘管爲臨時使用創建專門的表格會很麻煩。 – 2012-02-15 04:07:20