1

Using MySQL 5.5, I am able to execute the CREATE TABLE and INSERT queries individually but when I put them in a .sql script I receive the following error twice:

ERROR 1064 (42000): You have an error in your SQL syntax;

I tried to use the GO statement as recommended here (SQL script doesnt work but individual queries work) but no luck.

Here's my now working script thanks to comments:

-- 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);

Thanks for your help!

Here's the complete error message:

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
9
  • That other question is for SQL Server, not MySQL. Commented Oct 22, 2013 at 20:55
  • Uhm, GO is not for MySQL, isn't that something for MSSQL? Commented Oct 22, 2013 at 20:55
  • What is the complete error message you get? Commented Oct 22, 2013 at 20:55
  • If that's MySQL, remove GO :) Commented Oct 22, 2013 at 20:56
  • After removing GO, I still received the same error messages. Commented Oct 22, 2013 at 20:59

1 Answer 1

2

The -- syntax for mysql comments includes a space. --word is not a comment, but -- word is. The space is important.

I can't find any documentation for GO, but based on our error messages it actually works. You don't need it though. A semicolon, ;, does the same.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.