MySQL脚本抛出多个语法问题

时间:2017-09-28 15:36:15

标签: mysql sql database database-design datatable

我的SQL脚本出现了学校作业的问题。我相信可能存在某种模式或可能存在MySQL语法错误,但我不明白所显示的错误是什么。我是SQL新手。请帮助我理解我做错了什么,并指导我正确的方向。我的代码是创建表,为脚本赋值,然后输出所有表中的所有信息,输出两个行实例,然后使用外键使用join关键字执行两个连接。这是我的剧本:

SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';

DROP SCHEMA IF EXISTS PiqueExpenses
CREATE SCHEMA IF NOT EXISTS PiqueExpenses DEFAULT CHARACTER SET utf8 ;
USE PiqueExpenses

DROP TABLE IF EXISTS PiqueExpenses.JobPay
CREATE TABLE IF NOT EXISTS PiqueExpenses.JobPay (
    job_name VARCHAR(45) NOT NULL,
    pay_rate DOUBLE NULL,
    pay_hrs_worked DOUBLE NULL,
    job_mileage DOUBLE NULL,    
    pay_per_mile DOUBLE NULL,   
  PRIMARY KEY (job_name))
ENGINE = InnoDB;

DROP TABLE IF EXISTS PiqueExpenses.Jobs
CREATE TABLE IF NOT EXISTS PiqueExpenses.Jobs (
    job_id INT NOT NULL,
    job_name VARCHAR(45) NULL,
    job_type VARCHAR(45) NULL,
  PRIMARY KEY (job_id)
  INDEX fk_Jobs_JobPay_idx (job_name ASC),
  CONSTRAINT fk_Jobs_JobPay
    FOREIGN KEY (job_name)
    REFERENCES PiqueExpenses.JobPay (job_name)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

DROP TABLE IF EXISTS PiqueExpenses.Employee
CREATE TABLE IF NOT EXISTS PiqueExpenses.Employee (
    emp_id INT NOT NULL,
    job_id INT NULL,
    emp_address VARCHAR(45) NULL,
    emp_city VARCHAR(45) NULL,
    emp_state VARCHAR(45) NULL,
    emp_zip INT NULL,
    emp_phone_num VARCHAR(45) NULL,
  PRIMARY KEY (emp_id))
  INDEX fk_Employee_Jobs_idx (emp_id ASC),
  CONSTRAINT fk_Employee_Jobs
    FOREIGN KEY (emp_id)
    REFERENCES PiqueExpenses.Jobs (emp_id)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

DROP TABLE IF EXISTS PiqueExpenses.EmployeeNames
CREATE TABLE IF NOT EXISTS PiqueExpenses.EmployeeNames (
    emp_fname VARCHAR(45) NOT NULL,
    emp_initial VARCHAR(45) NULL,
    emp_lname VARCHAR(45) NULL,
    emp_id INT NULL,    
  PRIMARY KEY (emp_fname)
  PRIMARY KEY (emp_initial)
  PRIMARY KEY (emp_lname))
  INDEX fk_EmployeeNames_Employee_idx (emp_id ASC),
  CONSTRAINT fk_EmployeeNames_Employee
    FOREIGN KEY (emp_id)
    REFERENCES PiqueExpenses.Employee (emp_id)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

DROP TABLE IF EXISTS PiqueExpenses.Customer
CREATE TABLE IF NOT EXISTS PiqueExpenses.Customer (
    cust_id INT NOT NULL,
    emp_id INT NULL,
    cust_address VARCHAR(45) NULL,
    cust_city VARCHAR(45) NULL,
    cust_state VARCHAR(45) NULL,
    cust_zip INT NULL,
    cust_phone_num VARCHAR(45) NULL,
  PRIMARY KEY (cust_id))
  INDEX fk_Customer_Employee_idx (cust_phone_num ASC),
  CONSTRAINT fk_Customer_Employee
    FOREIGN KEY (cust_phone_num)
    REFERENCES PiqueExpenses.Employee (cust_phone_num)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

DROP TABLE IF EXISTS PiqueExpenses.CustomerNames
CREATE TABLE IF NOT EXISTS PiqueExpenses.CustomerNames (
    cust_fname VARCHAR(45) NOT NULL,
    cust_initial VARCHAR(45) NULL,
    cust_lname VARCHAR(45) NULL,
    cust_id INT NULL,
  PRIMARY KEY (cust_fname)
  PRIMARY KEY (cust_initial)
  PRIMARY KEY (cust_lname))
  INDEX fk_CustomerNames_Customer_idx (order_tran_id ASC),
  CONSTRAINT fk_CustomerNames_Customer
    FOREIGN KEY (order_tran_id)
    REFERENCES PiqueExpenses.Customer (order_tran_id)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;

START TRANSACTION;
USE PiqueExpenses;
INSERT INTO PiqueExpenses.JobPay (job_name, pay_rate, pay_hrs_worked, 
job_mileage, pay_per_mile) VALUES ('CCTV', 32.00, 4, 48.0, .53);
INSERT INTO PiqueExpenses.JobPay (job_name, pay_rate, pay_hrs_worked, 
job_mileage, pay_per_mile) VALUES ('Network', 29.50, 3.8, 35.0, .44);
INSERT INTO PiqueExpenses.JobPay (job_name, pay_rate, pay_hrs_worked, 
job_mileage, pay_per_mile) VALUES ('Alarm', 38.75, 7.6, 49.0, .48);
INSERT INTO PiqueExpenses.JobPay (job_name, pay_rate, pay_hrs_worked, 
job_mileage, pay_per_mile) VALUES ('DigitalMenuBoard', 42.00, 8.9, 21.0, 
.25);
INSERT INTO PiqueExpenses.JobPay (job_name, pay_rate, pay_hrs_worked, 
job_mileage, pay_per_mile) VALUES ('Telecom', 31.42, 3.5, 64.0, .58);
INSERT INTO PiqueExpenses.JobPay (job_name, pay_rate, pay_hrs_worked, 
job_mileage, pay_per_mile) VALUES ('DigitalMenuBoard', 42.00, 5.6, 82.0, 
.57);
INSERT INTO PiqueExpenses.JobPay (job_name, pay_rate, pay_hrs_worked, 
job_mileage, pay_per_mile) VALUES ('Alarm', 38.75, 6.7, 57.0, .57);
INSERT INTO PiqueExpenses.JobPay (job_name, pay_rate, pay_hrs_worked, 
job_mileage, pay_per_mile) VALUES ('Telecom', 31.42, 4.8, 66.0, .61);
INSERT INTO PiqueExpenses.JobPay (job_name, pay_rate, pay_hrs_worked, 
job_mileage, pay_per_mile) VALUES ('Network', 29.50, 4.4, 52.0, .49);
INSERT INTO PiqueExpenses.JobPay (job_name, pay_rate, pay_hrs_worked, 
job_mileage, pay_per_mile) VALUES ('CCTV', 32.00, 6.4, 70.0, .50);

COMMIT;

START TRANSACTION;
USE PiqueExpenses;
INSERT INTO PiqueExpenses.Jobs (job_id, job_name, job_type) VALUES (0001, 
'CCTV', 'Install');
INSERT INTO PiqueExpenses.Jobs (job_id, job_name, job_type) VALUES (0002, 
'Network','Install');
INSERT INTO PiqueExpenses.Jobs (job_id, job_name, job_type) VALUES (0003, 
'Alarm', 'Time&Mater');
INSERT INTO PiqueExpenses.Jobs (job_id, job_name, job_type) VALUES (0004, 
'DigitalMenuBoard', 'Install');
INSERT INTO PiqueExpenses.Jobs (job_id, job_name, job_type) VALUES (0005, 
'Telecom', 'Troubleshoot');
INSERT INTO PiqueExpenses.Jobs (job_id, job_name, job_type) VALUES (0004, 
'DigitalMenuBoard', 'Install');
INSERT INTO PiqueExpenses.Jobs (job_id, job_name, job_type) VALUES (0003, 
'Alarm', 'Troubleshoot');
INSERT INTO PiqueExpenses.Jobs (job_id, job_name, job_type) VALUES (0005, 
'Telecom', 'Troubleshoot');
INSERT INTO PiqueExpenses.Jobs (job_id, job_name, job_type) VALUES (0002, 
'Network', 'Troubleshoot');
INSERT INTO PiqueExpenses.Jobs (job_id, job_name, job_type) VALUES (0001, 
'CCTV', 'Install');

COMMIT;

START TRANSACTION;
USE PiqueExpenses;
INSERT INTO PiqueExpenses.Employee (emp_id, job_id, emp_address, emp_city, 
emp_state, emp_phone_num) VALUES (44201, 0001, '7613 Bellflower', 'Mentor', 
'OH', '44060', '1-(440)654-7744');
INSERT INTO PiqueExpenses.Employee (emp_id, job_id, emp_address, emp_city, 
emp_state, emp_phone_num) VALUES (44202, 0002, '2346 15th', 'Akron', 'OH', 
'44314', '1-(330)848-9413');
INSERT INTO PiqueExpenses.Employee (emp_id, job_id, emp_address, emp_city, 
emp_state, emp_phone_num) VALUES (44203, 0003, '6915 Giddings', 'Atwater', 
'OH', '44201', '1-(330)358-2026');
INSERT INTO PiqueExpenses.Employee (emp_id, job_id, emp_address, emp_city, 
emp_state, emp_phone_num) VALUES (44204, 0004, '11241 Mahoning', 'North 
Jackson', 'OH', '44451', '1-(330)666-9283');
INSERT INTO PiqueExpenses.Employee (emp_id, job_id, emp_address, emp_city, 
emp_state, emp_phone_num) VALUES (44205, 0005, '685 Deercrest', 'Wadsworth', 
'OH', '44281', '1-(330)954-2209');
INSERT INTO PiqueExpenses.Employee (emp_id, job_id, emp_address, emp_city, 
emp_state, emp_phone_num) VALUES (44206, 0004, '675 Wolf Ledges', 'Akron', 
'OH', '44309', '1-(330)996-9756');
INSERT INTO PiqueExpenses.Employee (emp_id, job_id, emp_address, emp_city, 
emp_state, emp_phone_num) VALUES (44207, 0003, '111 Center', 'Medina', 'OH', 
'44256', '1-(330)335-1803');
INSERT INTO PiqueExpenses.Employee (emp_id, job_id, emp_address, emp_city, 
emp_state, emp_phone_num) VALUES (44208, 0005, '222 State', 'Cuyahoga 
Falls', 'OH', '44223', '1-(330)388-6354');
INSERT INTO PiqueExpenses.Employee (emp_id, job_id, emp_address, emp_city, 
emp_state, emp_phone_num) VALUES (44209, 0002, '489 Bridge', 'Brimfield', 
'OH', '44240', '1-(330)321-6223');
INSERT INTO PiqueExpenses.Employee (emp_id, job_id, emp_address, emp_city, 
emp_state, emp_phone_num) VALUES (44210, 0001, '44 Chitauqua', 'Cleveland', 
'OH', '44134', '1-(678)980-0852');

COMMIT;

START TRANSACTION;
USE PiqueExpenses;
INSERT INTO PiqueExpenses.EmployeeNames (emp_fname, emp_initial, emp_lname, 
emp_id) VALUES ('Tom', 'I', 'Butler', 44201);
INSERT INTO PiqueExpenses.EmployeeNames (emp_fname, emp_initial, emp_lname, 
emp_id) VALUES ('Marty', 'M', 'Tucker', 44202);
INSERT INTO PiqueExpenses.EmployeeNames (emp_fname, emp_initial, emp_lname, 
emp_id) VALUES ('Tammy', 'T', 'Rivera', 44203);                                                                                                                                                                                                                                                                                                                                                              
S
INSERT INTO PiqueExpenses.EmployeeNames (emp_fname, emp_initial, emp_lname, 
emp_id) VALUES ('Alicia', 'L', 'Robinson', 44204);
INSERT INTO PiqueExpenses.EmployeeNames (emp_fname, emp_initial, emp_lname, 
emp_id) VALUES ('Mary', 'J', 'Watson', 44205);
INSERT INTO PiqueExpenses.EmployeeNames (emp_fname, emp_initial, emp_lname, 
emp_id) VALUES ('Rachel', 'J', 'Owens', 44206);
INSERT INTO PiqueExpenses.EmployeeNames (emp_fname, emp_initial, emp_lname, 
emp_id) VALUES ('Barb', 'L', 'Wright', 44207);
INSERT INTO PiqueExpenses.EmployeeNames (emp_fname, emp_initial, emp_lname, 
emp_id) VALUES ('Peter', 'F', 'Parker', 44208);
INSERT INTO PiqueExpenses.EmployeeNames (emp_fname, emp_initial, emp_lname, 
emp_id) VALUES ('Kathy', 'W', 'Alvarez', 44209);
INSERT INTO PiqueExpenses.EmployeeNames (emp_fname, emp_initial, emp_lname, 
emp_id) VALUES ('Frank', 'M', 'Morris', 44210);

COMMIT;

START TRANSACTION;
USE PiqueExpenses;
INSERT INTO PiqueExpenses.Customer (cust_id, emp_id, cust_address, 
cust_city, cust_state, cust_zip, cust_phone_num) VALUES (22001, 44201, '4123 
Anniversary Road', 'Nashville', 'TN', '37215', '1-(615)995-7744');
INSERT INTO PiqueExpenses.Customer (cust_id, emp_id, cust_address, 
cust_city, cust_state, cust_zip, cust_phone_num) VALUES (22002, 44202, '9807 
Ruskin Crossing', 'Bellevue', 'WA', '98008', '1-(425)975-9413');
INSERT INTO PiqueExpenses.Customer (cust_id, emp_id, cust_address, 
cust_city, cust_state, cust_zip, cust_phone_num) VALUES (22003, 44203, '39 
Montana Parkway', 'Saint Paul', 'MN', '55166', '1-(651)866-2047');
INSERT INTO PiqueExpenses.Customer (cust_id, emp_id, cust_address, 
cust_city, cust_state, cust_zip, cust_phone_num) VALUES (22004, 44204, '3 
Westridge Street', 'Stamford', 'CT', '06905', '1-(203)677-2492');
INSERT INTO PiqueExpenses.Customer (cust_id, emp_id, cust_address, 
cust_city, cust_state, cust_zip, cust_phone_num) VALUES (22005, 44205, '659 
Homewood Junction', 'Gary', 'IN', '46406', '1-(219)971-2522');
INSERT INTO PiqueExpenses.Customer (cust_id, emp_id, cust_address, 
cust_city, cust_state, cust_zip, cust_phone_num) VALUES (22006, 44206, 
'86460 Kensington Place', 'Columbus', 'OH', '43240', '1-(614)282-8239');
INSERT INTO PiqueExpenses.Customer (cust_id, emp_id, cust_address, 
cust_city, cust_state, cust_zip, cust_phone_num) VALUES (22007, 44207, '4360 
Bluestem Pass', 'Bradenton', 'FL', '34205', '1-(941)335-5180');
INSERT INTO PiqueExpenses.Customer (cust_id, emp_id, cust_address, 
cust_city, cust_state, cust_zip, cust_phone_num) VALUES (22008, 44208, '0178 
Hallows Pass', 'San Antonio', 'TX', '78265', '1-(210)523-6354');
INSERT INTO PiqueExpenses.Customer (cust_id, emp_id, cust_address, 
cust_city, cust_state, cust_zip, cust_phone_num) VALUES (22009, 44209, '1816 
Trailsway Alley', 'Sacramento', 'CA', '94245', '1-(916)618-3467');
INSERT INTO PiqueExpenses.Customer (cust_id, emp_id, cust_address, 
cust_city, cust_state, cust_zip, cust_phone_num) VALUES (22010, 44210, 
'72464 Armistice Drive', 'San Jose', 'CA', '95133', '1-(408)405-1270');

COMMIT;

START TRANSACTION;
USE PiqueExpenses;
INSERT INTO PiqueExpenses.CustomerNames (cust_fname, cust_initial, 
cust_lname, cust_id) VALUES ('Fred', 'F', 'Flinstone', 22001);
INSERT INTO PiqueExpenses.CustomerNames (cust_fname, cust_initial, 
cust_lname, cust_id) VALUES ('Buford', 'L', 'Tannen', 22002);
INSERT INTO PiqueExpenses.CustomerNames (cust_fname, cust_initial, 
cust_lname, cust_id) VALUES ('Yosimite', 'P', 'Sam', 22003);
INSERT INTO PiqueExpenses.CustomerNames (cust_fname, cust_initial, 
cust_lname, cust_id) VALUES ('John', 'A', 'Wayne', 22004);
INSERT INTO PiqueExpenses.CustomerNames (cust_fname, cust_initial, 
cust_lname, cust_id) VALUES ('James', 'K', 'Hetfield', 22005);
INSERT INTO PiqueExpenses.CustomerNames (cust_fname, cust_initial, 
cust_lname, cust_id) VALUES ('Lars', 'P', 'Ulrich', 22006);
INSERT INTO PiqueExpenses.CustomerNames (cust_fname, cust_initial, 
cust_lname, cust_id) VALUES ('Kirk', 'Q', 'Hammet', 22007);
INSERT INTO PiqueExpenses.CustomerNames (cust_fname, cust_initial, 
cust_lname, cust_id) VALUES ('Robert', 'F', 'Trajillo', 22008);
INSERT INTO PiqueExpenses.CustomerNames (cust_fname, cust_initial, 
cust_lname, cust_id) VALUES ('Alfred', 'P', 'Yankovich', 22009);
INSERT INTO PiqueExpenses.CustomerNames (cust_fname, cust_initial, 
cust_lname, cust_id) VALUES ('Odell', 'X', 'Beckham', 22010);

COMMIT;

START TRANSACTION;
USE PiqueExpenses;

SELECT  * 
FROM    JobPay, 
        Jobs, 
        EmployeeNames, 
        Employee, 
        CustomerNames, 
        Customer;

SELECT  * 
FROM    JobPay 
WHERE   job_name = 'Alarm';

SELECT  * 
FROM    Jobs 
WHERE   job_type = 'Install';

SELECT *
FROM Jobs
LEFT OUTER JOIN JobPay ON Jobs.job_name = JobPay.job_name

UNION

SELECT *
FROM Jobs
RIGHT OUTER JOIN JobPay ON Jobs.job_name = JobPay.job_name;

SELECT *
FROM Customer
LEFT OUTER JOIN CustomerNames ON Customer.cust_id = CustomerNames.cust_id

UNION

SELECT *
FROM Customer
RIGHT OUTER JOIN CustomerNames ON Customer.cust_id = CustomerNames.cust_id;

以下是错误: 错误代码:1064。您的SQL语法有错误;检查与您的MySQL服务器版本相对应的手册,以便在#" CREATE SCHEMA(如果不是EXISTS PTIExpenses默认字符集)中使用正确的语法设置utf8'在第2行

错误代码:1064。您的SQL语法有错误;查看与您的MySQL服务器版本相对应的手册,以便在正确的语法附近使用' DROP TABLE IF EXISTS PiqueExpenses.JobPay CREATE TABLE IF NOT EXISTS PiqueExpens'在第3行

错误代码:1064。您的SQL语法有错误;查看与您的MySQL服务器版本相对应的手册,以便使用“#99; CREATE TABLE IF NOT NOT EXISTS PiqueExpenses.Jobs”(job_id INT NOT NULL,job_name' at line 2

错误代码:1064。您的SQL语法有错误;查看与您的MySQL服务器版本相对应的手册,以便使用正确的语法,如果没有EXTITS PiqueExpenses.Employee,则使用CREATE TABLE(emp_id INT NOT NULL,job_i' at line 2

错误代码:1064。您的SQL语法有错误;查看与您的MySQL服务器版本相对应的手册,以便在#2; CREATE TABLE IF NOT EXISTS PiqueExpenses.EmployeeNames(emp_fname VARCHAR(45)'第2行)附近使用正确的语法

错误代码:1064。您的SQL语法有错误;检查与您的MySQL服务器版本相对应的手册,以便使用正确的语法,如果不是EXISTS,则使用CREATE TABLE PiqueExpenses.Customer(cust_id INT NOT NULL,emp _' at line 2

错误代码:1064。您的SQL语法有错误;查看与您的MySQL服务器版本相对应的手册,以便在#2; CREATE TABLE IF NOT EXISTS PiqueExpenses.CustomerNames(cust_fname VARCHAR(45)'第2行)附近使用正确的语法

1个警告:3135' NO_ZERO_DATE',' NO_ZERO_IN_DATE'和' ERROR_FOR_DIVISION_BY_ZERO' sql模式应该与严格模式一起使用。它们将在未来版本中与严格模式合并。

错误代码:1049。未知数据库' piqueexpenses'

错误代码:1146。表' piqueexpenses.jobpay'不存在

错误代码:1049。未知数据库' piqueexpenses'

错误代码:1146。表' piqueexpenses.jobs'不存在

错误代码:1146。表' piqueexpenses.employee'不存在

错误代码:1146。表' piqueexpenses.employeenames'不存在

错误代码:1146。表' piqueexpenses.customer'不存在

错误代码:1146。表' piqueexpenses.customernames'不存在

错误代码:1046。未选择数据库通过在侧栏的SCHEMAS列表中双击其名称来选择要使用的默认数据库。

错误代码:1064。您的SQL语法有错误;检查与您的MySQL服务器版本相对应的手册,以便在#" CREATE SCHEMA(如果不是EXISTS PTIExpenses默认字符集)中使用正确的语法设置utf8'在第2行

0行受影响,1警告:3135' NO_ZERO_DATE',' NO_ZERO_IN_DATE'和' ERROR_FOR_DIVISION_BY_ZERO' sql模式应该与严格模式一起使用。它们将在未来版本中与严格模式合并。

错误代码:1146。表' piqueexpenses.jobpay'不存在

错误代码:1146。表' piqueexpenses.jobs'不存在

错误代码:1146。表' piqueexpenses.employee'不存在

错误代码:1146。表' piqueexpenses.employeenames'不存在

错误代码:1146。表' piqueexpenses.customer'不存在

错误代码:1146。表' piqueexpenses.customernames'不存在

错误代码:1046。未选择数据库通过在侧栏的SCHEMAS列表中双击其名称来选择要使用的默认数据库。

错误代码:1064。您的SQL语法有错误;检查与您的MySQL服务器版本相对应的手册,以便在#" CREATE SCHEMA(如果不是EXISTS PTIExpenses默认字符集)中使用正确的语法设置utf8'在第2行

错误代码:1064。您的SQL语法有错误;查看与您的MySQL服务器版本相对应的手册,以便在正确的语法附近使用' DROP TABLE IF EXISTS PiqueExpenses.JobPay CREATE TABLE IF NOT EXISTS PiqueExpens'在第3行

错误代码:1064。您的SQL语法有错误;查看与您的MySQL服务器版本相对应的手册,以便使用“#99; CREATE TABLE IF NOT NOT EXISTS PiqueExpenses.Jobs”(job_id INT NOT NULL,job_name' at line 2

错误代码:1064。您的SQL语法有错误;查看与您的MySQL服务器版本相对应的手册,以便使用正确的语法,如果没有EXTITS PiqueExpenses.Employee,则使用CREATE TABLE(emp_id INT NOT NULL,job_i' at line 2

错误代码:1064。您的SQL语法有错误;查看与您的MySQL服务器版本相对应的手册,以便在#2; CREATE TABLE IF NOT EXISTS PiqueExpenses.EmployeeNames(emp_fname VARCHAR(45)'第2行)附近使用正确的语法

错误代码:1064。您的SQL语法有错误;检查与您的MySQL服务器版本相对应的手册,以便使用正确的语法,如果不是EXISTS,则使用CREATE TABLE PiqueExpenses.Customer(cust_id INT NOT NULL,emp _' at line 2

错误代码:1064。您的SQL语法有错误;查看与您的MySQL服务器版本相对应的手册,以便在#2; CREATE TABLE IF NOT EXISTS PiqueExpenses.CustomerNames(cust_fname VARCHAR(45)'第2行)附近使用正确的语法

0行受影响,1警告:3135' NO_ZERO_DATE',' NO_ZERO_IN_DATE'和' ERROR_FOR_DIVISION_BY_ZERO' sql模式应该与严格模式一起使用。它们将在未来版本中与严格模式合并。

1 个答案:

答案 0 :(得分:0)

您尚未使用分号

终止每个 DROP
    #MySQL 5.7.12

    SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
    SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
    SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';

    DROP TABLE IF EXISTS JobPay;
    CREATE TABLE IF NOT EXISTS JobPay (
        job_name VARCHAR(45) NOT NULL,
        pay_rate DOUBLE NULL,
        pay_hrs_worked DOUBLE NULL,
        job_mileage DOUBLE NULL,    
        pay_per_mile DOUBLE NULL,   
      PRIMARY KEY (job_name))
    ENGINE = InnoDB;

    DROP TABLE IF EXISTS Jobs;
    CREATE TABLE IF NOT EXISTS Jobs (
        job_id INT NOT NULL,
        job_name VARCHAR(45) NULL,
        job_type VARCHAR(45) NULL,
      PRIMARY KEY (job_id)
      INDEX fk_Jobs_JobPay_idx (job_name ASC),
      CONSTRAINT fk_Jobs_JobPay
        FOREIGN KEY (job_name)
        REFERENCES PiqueExpenses.JobPay (job_name)
        ON DELETE NO ACTION
        ON UPDATE NO ACTION)
    ENGINE = InnoDB;

遇到许多错误时,请减少问题的严重程度,直到您检测到第一个错误为止。处理该错误,然后添加更多代码,直到找到下一个错误。处理该错误,然后添加更多代码,直到找到下一个错误。重复直到完成。

即。将你的代码视为萨拉米香肠,将其切成小块切片

我没有尝试测试代码的每一部分,但很明显,那些引用DROP的行首先需要帮助。