0

I'm not very familiar with sql, so I'm using workbench to create a db. I keep getting this error:

Executing SQL script in server
ERROR: Error 1064: 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 ')
    REFERENCES `project2`.`REF` ()
    ON DELETE CASCADE
    ON UPDATE CASCADE' at line 6
SQL Code:
        CREATE TABLE IF NOT EXISTS `project2`.`REF_AUTH` (
          `REF#` INT(11) NOT NULL AUTO_INCREMENT,
          `RAUTHOR` VARCHAR(45) NOT NULL,
          PRIMARY KEY (`REF#`, `RAUTHOR`),
          CONSTRAINT `REF#`
            FOREIGN KEY ()
            REFERENCES `project2`.`REF` ()
            ON DELETE CASCADE
            ON UPDATE CASCADE)
        ENGINE = InnoDB
        DEFAULT CHARACTER SET = big5

SQL script execution finished: statements: 4 succeeded, 1 failed

Any help would be greatly appreciated.

0

Give this a try, your issue was the syntax with the foreign key and the references.

CREATE TABLE IF NOT EXISTS `project2`.`REF_AUTH` (
  `REF#` INT(11) NOT NULL AUTO_INCREMENT,
  `RAUTHOR` VARCHAR(45) NOT NULL,
   PRIMARY KEY (`REF#`, `RAUTHOR`),
   CONSTRAINT `REF#`
      FOREIGN KEY (`REF#`) REFERENCES `REF` (`REF#`) 
      ON DELETE CASCADE
      ON UPDATE CASCADE)
   ENGINE = InnoDB
   DEFAULT CHARACTER SET = big5

Syntax link

Another helpful link

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.