2016-12-08 103 views
0

我正在使用mysql並且不斷收到錯誤。我認爲這是因爲我沒有備用鑰匙,但我不知道如何設置鑰匙。錯誤:錯誤1064:您的SQL語法中有錯誤

CREATE TABLE IF NOT EXISTS `Employee`.`Employee` (
      `PersonId` INT NOT NULL, 
      `EmployeeID` INT NOT NULL, 
      `FName` VARCHAR(45) NOT NULL, 
      `MName` VARCHAR(45) NOT NULL, 
      `LName` VARCHAR(60) NOT NULL, 
      `DOB` DATE NOT NULL, 
      `Gender` VARCHAR(1) NOT NULL, 
      `Enthnicity` VARCHAR(45) NOT NULL, 
      `PersonalEmail` VARCHAR(100) NULL, 
      `WorkEmail` VARCHAR(100) NULL, 
      `Department` VARCHAR(30) NULL, 
      `Building` VARCHAR(20) NOT NULL, 
      `OfficeNumber` VARCHAR(10) NOT NULL, 
      PRIMARY KEY (`PersonId`), 
      UNIQUE INDEX `EmployeeID_UNIQUE` (`EmployeeID` ASC), 
      UNIQUE INDEX `PersonalEmail_UNIQUE` (`PersonalEmail` ASC), 
      UNIQUE INDEX `WorkEmail_UNIQUE` (`WorkEmail` ASC), 
      CONSTRAINT `Department` 
      FOREIGN KEY() 
      REFERENCES `Employee`.`Department`() 
      ON DELETE NO ACTION 
      ON UPDATE NO ACTION) 
     ENGINE = InnoDB 

謝謝。

回答

0

首先創建表並在創建外鍵後!

CREATE TABLE IF NOT EXISTS `Employee`.`Employee` (
     `PersonId` INT NOT NULL, 
     `EmployeeID` INT NOT NULL, 
     `FName` VARCHAR(45) NOT NULL, 
     `MName` VARCHAR(45) NOT NULL, 
     `LName` VARCHAR(60) NOT NULL, 
     `DOB` DATE NOT NULL, 
     `Gender` VARCHAR(1) NOT NULL, 
     `Enthnicity` VARCHAR(45) NOT NULL, 
     `PersonalEmail` VARCHAR(100) NULL, 
     `WorkEmail` VARCHAR(100) NULL, 
     `Department` VARCHAR(30) NULL, 
     `Building` VARCHAR(20) NOT NULL, 
     `OfficeNumber` VARCHAR(10) NOT NULL, 
     PRIMARY KEY (`PersonId`), 
     UNIQUE INDEX `EmployeeID_UNIQUE` (`EmployeeID` ASC), 
     UNIQUE INDEX `PersonalEmail_UNIQUE` (`PersonalEmail` ASC), 
     UNIQUE INDEX `WorkEmail_UNIQUE` (`WorkEmail` ASC) 
    ) 
    ENGINE = InnoDB; 

使用Mysql工作臺或phpmyadmin進行mysql修改以節省時間,並忘記這個問題!

相關問題