MySQL错误1064(42000)脚本插入

时间:2015-02-21 23:12:19

标签: mysql mysql-error-1064 insert-into

我在加载数据后输入的任何插入语句都收到错误。我已经尝试重新排列插入语句但仍然收到错误。不知道该怎么做,任何帮助都会很棒!

错误是:Error: "Error 1064 (42000): ... right syntax to use near '--Load data Insert into Branches(Name,Adress,Phone) Values('North','123 sout' at line 1

SQL如下:

Drop Database If exists HW2;
Create Database HW2;
use HW2

# Defining Tables 

CREATE TABLE Branches(
Name VARCHAR(30),
Address VARCHAR(45),
Phone Char(10),
PRIMARY KEY(Name));

Create Table Employees(
ID Char(10),
fName Varchar(10),
mName Varchar(10),
lName Varchar(10),
address Varchar(35),
ssn char(9),
phone char(10),
jobTitle Varchar(20),
salary varchar(6),
Primary Key(ID));

create table Members(
ID char(10),
fname varchar(20),
mName varchar(20),
lName varchar(20),
phone char(10),
address varchar(35),
birthday Date,
Primary Key(ID));

create table BooksCheckOut(
booksID Char(10),
membersID char(10) NOT NULL,
checkOutDate Date,
returnDate Date, 
costLate Varchar(5),
title varchar(20),
publishYr year(4),
location varchar(30),
status varchar(25),
category varchar(30),
publisher varchar(30),
costLoss varchar(5),
Primary Key(booksID),
foreign key(membersID) references Members(ID));

create table printBooks(
ID char(10), 
ISBN varchar(13),
Primary Key(ID),
Foreign Key(ID) References BooksCheckOut(booksID));

create table AudioBooks(
ID char(10),
ASI varchar(13),
narrator varchar(25),
listenLength varchar(5),
lang varchar(25),
Primary Key(ID),
Foreign Key(ID) References BooksCheckOut(booksID));

create table Authors(
ID char(10),
fName varchar(20),
mName varchar(20),
lName varchar(20),
Primary Key(ID));

create table writes(
aID char(10),
bcheckID char(10),
primary Key(aID,bcheckID),
foreign key (aID) references Authors(ID),
foreign key(bcheckID) references BooksCheckOut(booksID));


create table stores(
branchName varchar(30),
booksID char(10),
primary key(branchName, booksID),
foreign key(branchName) references Branches(name),
foreign key(booksID) references BooksCheckOut(booksID));


create table WorksAt(
empID char(10),
branchName varchar(30),
primary key(empID, branchName),
foreign key(empID) references Employees(ID),
foreign key(branchName) references Branches(name));

--Load data 

Insert into Branches(Name,Address,Phone) 
Values('North','123 south road California 90210','2332551234'),
('South','123 south road California 90210','2332551234'),
('West','123 south road California 90210','2332551234'),
('East','123 south road California 90210','2332551234'),
('NorthEast','123 south road California 90210','2332551234');

Insert Into Employees(ID,fName,mName,lName,address,ssn,phone,jobTitle,salary) 
Values('1234567891','John','Jane','Doe','8701 green street NC 27411','123456789','1123456789','SalesRep','65000'),
('1234567892','John','Jane','Doe','8701 green street NC 27411','123456789','1123456789','SalesRep','65000'),
('1234567893','John','Jane','Doe','8701 green street NC 27411','123456789','1123456789','SalesRep','65000'),
('1234567894','John','Jane','Doe','8701 green street NC 27411','123456789','1123456789','SalesRep','65000'),
('1234567895','John','Jane','Doe','8701 green street NC 27411','123456789','1123456789','SalesRep','65000');

Insert into Members(ID,fName,mName,lName,phone,address,birthday)
Values('9876543211','David', 'Thomas','Hoy','3211234561','3214 green road NC 25252','1995-04-21'),
('9876543212','David', 'Thomas','Hoy','3211234561','3214 green road NC 25252','1995-04-21'),
('9876543213','David', 'Thomas','Hoy','3211234561','3214 green road NC 25252','1995-04-21'),
('9876543214','David', 'Thomas','Hoy','3211234561','3214 green road NC 25252','1995-04-21'),
('9876543215','David', 'Thomas','Hoy','3211234561','3214 green road NC 25252','1995-04-21');

Insert into BooksCheckOut(booksID,membersID,checkOutDate,returnDate,costLate,title,publishYr,location,status,category,publisher,costLoss)
Values('1010101010', '9876543211','2009-04-13','2009-04-14','5.00','Catcher','2005','California','In Stock', 'Non-Fiction', 'Pearson','1.00'),
('1010101011', '9876543212','2009-04-13','2009-04-14','5.00','Catcher','2005','California','In Stock', 'Non-Fiction', 'Pearson','1.00'),
('1010101012', '9876543213','2009-04-13','2009-04-14','5.00','Catcher','2005','California','In Stock', 'Non-Fiction', 'Pearson','1.00'),
('1010101013', '9876543214','2009-04-13','2009-04-14','5.00','Catcher','2005','California','In Stock', 'Non-Fiction', 'Pearson','1.00'),
('1010101014', '9876543215','2009-04-13','2009-04-14','5.00','Catcher','2005','California','In Stock', 'Non-Fiction', 'Pearson','1.00');

Insert into printBooks(ID, ISBN) 
Values('1010101010','1234567891234'),
('1010101011','1234567891234'),
('1010101012','1234567891234'),
('1010101013','1234567891234'),
('1010101014','1234567891234');

Insert into AudioBooks(ID,ASI,narrator,listenLength,lang)
Values('1010101010','102013','Stephen King','5:00','English'),
('1010101011','102013','Stephen King','5:00','English'),
('1010101012','102013','Stephen King','5:00','English'),
('1010101013','102013','Stephen King','5:00','English'),
('1010101014','102013','Stephen King','5:00','English');


Insert into Authors(ID,fName,mName,lName)
Values('1020320101','Steve','Thomas','James'),
('1020320102', 'Steve','Thomas','James'),
('1020320103', 'Steve','Thomas','James'),
('1020320104', 'Steve','Thomas','James'),
('1020320105', 'Steve','Thomas','James');

Insert into stores(branchName,booksID)
Values('North','1010101010'),
('South','1010101011'),
('West','1010101012'),
('East','1010101013'),
('NorthEast','1010101014');

Insert into WorksAt(empID,branchName)
Values('1234567891','North'),
('1234567892','South'),
('1234567893','West'),
('1234567894','East'),
('1234567895','NorthEast');

Insert into writes(aID,bcheckID)
Values('1020320101','1010101010'),
('1020320102','1010101011'),
('1020320103','1010101012'),
('1020320104','1010101013'),
('1020320105','1010101014');

1 个答案:

答案 0 :(得分:0)

根据MySQL documentation,您必须在双击“ - ”之后放置空格或控制字符。

  

从“ - ”序列到行尾。支持此样式   从MySQL 3.23.3开始。在MySQL中,“ - ”(双破折号)评论样式   要求第二个破折号后跟至少一个空格或   控制字符(例如空格,制表符,换行符等)。这个   语法与标准SQL注释语法略有不同,如上所述   在第1.9.5.8节中,“' - '作为评论的开头”。

新代码:

-- Load Data