2013-10-22 24 views
1

使用MySQL 5.5,我能夠單獨執行CREATE TABLEINSERT查詢,但是當我把它們放在一個.sql腳本我收到以下錯誤兩次:無法執行.SQL腳本,但查詢單獨工作

錯誤1064(42000):您的SQL語法錯誤;

我試着按照這裏推薦的使用GO語句(SQL script doesnt work but individual queries work),但沒有運氣。

這裏是我現在的工作腳本感謝評論:

-- Create the table 
CREATE TABLE person (
    id INTEGER PRIMARY KEY, 
    first_name TEXT, 
    last_name TEXT, 
    age INTEGER 
); 

-- Populate the table 
INSERT INTO person 
(id, first_name, last_name, age) 
VALUES 
    (0, 'Zed', 'Shaw', 37), 
    (1, 'Terry', 'Berry', 42), 
    (2, 'Tyler', 'Brown', 25), 
    (3, 'Frank', 'Smith', 100); 

感謝您的幫助!

以下是完整的錯誤消息:

mysql> SOURCE ~/code/Learn-SQL-The-Hard-Way/Exercise-12-Destroying-And-Altering-Tables/recreate-person-table.sql 
ERROR 1064 (42000): 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 '--Create the table 
CREATE TABLE person (
    id INTEGER PRIMARY KEY, 
    first_n' at line 1 
ERROR: 
No query specified 

ERROR 1064 (42000): 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 '--Populate the table 
INSERT INTO person 
(id, first_name, last_name, age) 
VALUES 
' at line 1 
+0

另一個問題是SQL Server,而不是MySQL。 – Barmar

+0

Uhm,'GO'不適用於MySQL,對MSSQL來說不是那種東西嗎? – Darwind

+0

什麼是你得到的完整的錯誤信息? – Barmar

回答

2

The -- syntax for mysql comments包括空間。 --word不是註釋,但是-- word是。空間很重要。

我找不到GO的任何文檔,但根據我們的錯誤消息,它實際上工作。不過你並不需要它。分號;也是這樣。

相關問題