反斜杠会引发意外的语句错误

时间:2016-02-28 16:52:18

标签: mysql sql phpmyadmin

所以我有这个SQL脚本来批量加载我的数据:

INSERT INTO DeliveryMethod (deliveryMethod) 
VALUES ('Bicycle');
INSERT INTO DeliveryMethod (deliveryMethod) 
VALUES ('Car');
INSERT INTO DeliveryMethod (deliveryMethod) 
VALUES ('Van');
INSERT INTO DeliveryMethod (deliveryMethod) 
VALUES ('None');

SET foreign_key_checks = 0;

# Load data into categories
LOAD DATA LOCAL INFILE
'C:/Users/ryank/OneDrive/Documents/GitHub/DBMS-CW/R4/CategoryData.txt'
REPLACE INTO TABLE CourierDB.Category
FIELDS TERMINATED BY ','
LINES STARTING BY '(' TERMINATED BY ')\r'
(name)
SET categoryID = NULL; # Should trigger auto increment (or \r)

# Load data into package
LOAD DATA LOCAL INFILE
'C:/Users/ryank/OneDrive/Documents/GitHub/DBMS-CW/R4/PackageData.txt'
REPLACE INTO TABLE CourierDB.Package
FIELDS TERMINATED BY ','
LINES STARTING BY '(' TERMINATED BY ')\r'
(price, itemName, category)
SET packageID = NULL; # Should trigger auto increment (or \r)

# Load data into address
LOAD DATA LOCAL INFILE
'C:/Users/ryank/OneDrive/Documents/GitHub/DBMS-CW/R4/AddressData.txt'
REPLACE INTO TABLE CourierDB.Address
FIELDS TERMINATED BY ','
LINES STARTING BY '(' TERMINATED BY ')\r'
(buildingName, streetName, county, postcode)
SET addressID = NULL;

# Load data into packages
LOAD DATA LOCAL INFILE
'C:/Users/ryank/OneDrive/Documents/GitHub/DBMS-CW/R4/PackagesData.txt'
REPLACE INTO TABLE CourierDB.Packages
FIELDS TERMINATED BY ','
LINES STARTING BY '(' TERMINATED BY ')\r'
(packagesID, package);

# Load data into branch
LOAD DATA LOCAL INFILE
'C:/Users/ryank/OneDrive/Documents/GitHub/DBMS-CW/R4/BranchData.txt'
REPLACE INTO TABLE CourierDB.Branch
FIELDS TERMINATED BY ','
LINES STARTING BY '(' TERMINATED BY ')\r'
(branchName, address, headOfficeID, managerID, deliveryMethods)
SET branchID = NULL;

# Load data into consignment
LOAD DATA LOCAL INFILE
'C:/Users/ryank/OneDrive/Documents/GitHub/DBMS-CW/R4/ConsignmentData.txt'
REPLACE INTO TABLE CourierDB.Consignment
FIELDS TERMINATED BY ','
LINES STARTING BY '(' TERMINATED BY ')\r'
(dispatchDate, consignmentType, branch, deliveryAddressID, returnAddressID, packages)
SET trackingID = NULL;

# Load data into DeliveryMethods
LOAD DATA LOCAL INFILE
'C:/Users/ryank/OneDrive/Documents/GitHub/DBMS-CW/R4/DeliveryMethodsData.txt'
REPLACE INTO TABLE CourierDB.DeliveryMethods
FIELDS TERMINATED BY ','
LINES STARTING BY '(' TERMINATED BY ')\r'
(deliveryMethodID, deliveryMethod);

# Load data into Employee
LOAD DATA LOCAL INFILE
'C:/Users/ryank/OneDrive/Documents/GitHub/DBMS-CW/R4/EmployeeData.txt'
REPLACE INTO TABLE CourierDB.Employee
FIELDS TERMINATED BY ','
LINES STARTING BY '(' TERMINATED BY ')\r'
(NIN, firstName, lastName, dateOfBirth, emailAddress, mobileNo, salary, branchID, supervisorID, address)
SET staffNo = NULL;

# Load data into CustomerConsignments
LOAD DATA LOCAL INFILE
'C:/Users/ryank/OneDrive/Documents/GitHub/DBMS-CW/R4/CustomerConsignmentsData.txt'
REPLACE INTO TABLE CourierDB.CustomerConsignments
FIELDS TERMINATED BY ','
LINES STARTING BY '(' TERMINATED BY ')\r'
(consignmentsID, consignment);

# Load data into Customer
LOAD DATA LOCAL INFILE
'C:/Users/ryank/OneDrive/Documents/GitHub/DBMS-CW/R4/CustomerData.txt'
REPLACE INTO TABLE CourierDB.Customer
FIELDS TERMINATED BY ','
LINES STARTING BY '(' TERMINATED BY ')\r'
(firstName, lastName, dateOfBirth, emailAddress, mobileNo, customerBranchID, address, consignments)
SET customerID = NULL;
SET foreign_key_checks = 1;

然而,有了这个说...当我把它放入我的关系模式时,由于某种原因我在这里得到这个错误:

  

静态分析:

     

在分析过程中发现了3个错误。

     

意外的角色。 (位置0处的“\”附近)意外开始   声明。 (位置0处的“\”附近)语句的意外开头。   (位置1处的“r”附近)SQL查询:

     

\ r \ n LOAD DATA LOCAL INFILE   'C:/Users/ryank/OneDrive/Documents/GitHub/DBMS-CW/R4/PackageData.txt'   更换表CourierDB.Package FIELDS终止','LINES   起始''('终止于')\ r'(价格,项目名称,类别)SET   packageID = NULL

     

MySQL说:文档

     

1064 - 您的SQL语法出错;查看与MariaDB服务器版本对应的手册,以获取正确的语法   靠近'\ r \ n LOAD DATA LOCAL INFILE   第1行的'C:/ Users / ryank / OneDrive / Documents / GitHub / DBMS-CW / R4'

任何帮助将不胜感激!感谢

0 个答案:

没有答案