使用 MySQL 5.5,我可以单独执行CREATE TABLE
和INSERT
查询,但是当我将它们放入.sql
脚本中时,我两次收到以下错误:
ERROR 1064 (42000):您的 SQL 语法有错误;
我尝试使用此处推荐的 GO 语句(SQL 脚本不起作用,但个别查询起作用)但没有运气。
感谢评论,这是我现在工作的脚本:
-- 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