如何调试 MySQL 错误“#1064 - 你的 SQL 语法有错误”
How to debug the MySQL error "#1064 - You have an error in your SQL syntax"
我知道这个问题已被问过多次,但我是一个初学者,我正在将数据库从 SQL workbench 转移到 phpmyadmin。我不断收到此错误:
SQL查询:
CREATE TABLE IF NOT EXISTS `ApplicationSystem`.`staff` (
`StaffID` TEXT(6) NOT NULL,
`Name` VARCHAR(45) NULL,
`Email` VARCHAR(254) NULL,
`Password` VARCHAR(45) NULL,
PRIMARY KEY (`StaffID`),
CONSTRAINT `StaffID`
FOREIGN KEY ()
REFERENCES `ApplicationSystem`.`UserType` ()
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
MySQL said: Documentation
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')
REFERENCES `ApplicationSystem`.`UserType` ()
ON DELETE NO ACTION
' at line 8
这里是实际的 SQL 代码:
-- MySQL Script generated by MySQL Workbench
-- 04/04/16 23:56:12
-- Model: New Model Version: 1.0
-- MySQL Workbench Forward Engineering
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';
-- -----------------------------------------------------
-- Schema ApplicationSystem
-- -----------------------------------------------------
-- -----------------------------------------------------
-- Schema ApplicationSystem
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `ApplicationSystem` DEFAULT CHARACTER SET utf8 ;
USE `ApplicationSystem` ;
-- -----------------------------------------------------
-- Table `ApplicationSystem`.`staff`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `ApplicationSystem`.`staff` (
`StaffID` TEXT(6) NOT NULL,
`Name` VARCHAR(45) NULL,
`Email` VARCHAR(254) NULL,
`Password` VARCHAR(45) NULL,
PRIMARY KEY (`StaffID`),
CONSTRAINT `StaffID`
FOREIGN KEY ()
REFERENCES `ApplicationSystem`.`UserType` ()
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `ApplicationSystem`.`UserType`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `ApplicationSystem`.`UserType` (
`Type` ENUM('A', 'HA', 'AT') NULL,
`ID` TEXT(6) NOT NULL,
INDEX `ID_idx` (`ID` ASC),
PRIMARY KEY (`ID`),
UNIQUE INDEX `ID_UNIQUE` (`ID` ASC),
CONSTRAINT `ID`
FOREIGN KEY (`ID`)
REFERENCES `ApplicationSystem`.`Applicants` (`ApplicantID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `ID`
FOREIGN KEY (`ID`)
REFERENCES `ApplicationSystem`.`staff` (`StaffID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `ApplicationSystem`.`Applicants`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `ApplicationSystem`.`Applicants` (
`ApplicantID` TEXT(6) NULL,
`Firstname` VARCHAR(40) NULL,
`surname` VARCHAR(40) NULL,
`DOB` DATE NULL,
`Gender` ENUM('yes', 'no') NULL,
`Address` VARCHAR(45) NULL,
`Postcode` VARCHAR(9) NULL,
`ApplicantMobile` TEXT(11) NULL,
`ApplicantHome` TEXT(11) NULL,
`ApplicantEmail` VARCHAR(255) NULL,
`ParentName` VARCHAR(40) NULL,
`Relationtoapplicant` VARCHAR(15) NULL,
`ParentEmail` VARCHAR(255) NULL,
`ParentAddress` VARCHAR(40) NULL,
`ParentPostcode` VARCHAR(9) NULL,
`ParentHome` TEXT(11) NULL,
`ParentMobile` TEXT(11) NULL,
`Currentschool` VARCHAR(40) NULL,
`ApplicantInYr11` ENUM('yes', 'no') NULL,
`Sibbling` ENUM('yes', 'no') NULL,
`SibblingName` VARCHAR(40) NULL,
`SibblingYear` TEXT(2) NULL,
`MedicalConditions` VARCHAR(30) NULL,
`AccessArrangementsAvailable` ENUM('yes', 'no') NULL,
`AccessArrangments` VARCHAR(20) NULL,
`Ethnic` VARCHAR(40) NULL,
`FirstLanguage` VARCHAR(15) NULL,
`HomeLanguage` VARCHAR(15) NULL,
`Religion` VARCHAR(15) NULL,
`Nationality` VARCHAR(20) NULL,
`ArmedForces` ENUM('yes', 'no') NULL,
`PreviouslyLookedAfter` ENUM('yes', 'no') NULL,
`EUResident` ENUM('yes', 'no') NULL,
`RestrictionResidence` ENUM('yes', 'no') NULL,
`school1` VARCHAR(45) NULL,
`school2` VARCHAR(45) NULL,
`school3` VARCHAR(45) NULL,
`school4` VARCHAR(45) NULL,
`UPN` TEXT(13) NULL,
`UCL` TEXT(13) NULL,
`ULN` TEXT(10) NULL,
`Password` VARCHAR(40) NULL,
`Course1` VARCHAR(30) NULL,
`Course2` VARCHAR(30) NULL,
`Course3` VARCHAR(30) NULL,
`Course4` VARCHAR(30) NULL,
`Course5` VARCHAR(30) NULL,
`Complete` TINYINT(1) NULL,
`Outcome` ENUM('R', 'A') NULL,
PRIMARY KEY (`ApplicantID`),
UNIQUE INDEX `idtable1_UNIQUE` (`ApplicantID` ASC),
UNIQUE INDEX `ApplicantEmail_UNIQUE` (`ApplicantEmail` ASC),
CONSTRAINT `ApplicantID`
FOREIGN KEY ()
REFERENCES `ApplicationSystem`.`UserType` ()
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `ApplicationSystem`.`table1`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `ApplicationSystem`.`table1` (
`ID` TEXT(6) NOT NULL,
`outcome` TEXT(6) NULL,
PRIMARY KEY (`ID`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `ApplicationSystem`.`outcome`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `ApplicationSystem`.`outcome` (
`ID` TEXT(6) NOT NULL,
`Outcome` ENUM('R', 'A') NULL,
PRIMARY KEY (`ID`),
CONSTRAINT `ID`
FOREIGN KEY (`ID`)
REFERENCES `ApplicationSystem`.`Applicants` (`ApplicantID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
USE `ApplicationSystem` ;
-- -----------------------------------------------------
-- Placeholder table for view `ApplicationSystem`.`view1`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `ApplicationSystem`.`view1` (`id` INT);
-- -----------------------------------------------------
-- View `ApplicationSystem`.`view1`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `ApplicationSystem`.`view1`;
USE `ApplicationSystem`;
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS
FOREIGN KEY (`here shoud be the column name the key belongs to`)
CONSTRAINT `StaffID`
FOREIGN KEY ()
REFERENCES `ApplicationSystem`.`UserType` ()
要声明外键约束,您必须指明参与约束的具体列。你在这里没有这样做。正确的语法是
CONSTRAINT `StaffID`
FOREIGN KEY (<name of a column in this table>)
REFERENCES `ApplicationSystem`.`UserType` (<name of the matching column in the referenced table>)
用正确的实际列名填写<placeholders>
。
不过,塞巴斯说得有道理;数据不是 "in" 或 Workbench 或 phpMyAdmin;这些只是连接到数据库进程的管理客户端,因此您应该能够建立到现有数据库的新连接。
我知道这个问题已被问过多次,但我是一个初学者,我正在将数据库从 SQL workbench 转移到 phpmyadmin。我不断收到此错误:
SQL查询:
CREATE TABLE IF NOT EXISTS `ApplicationSystem`.`staff` (
`StaffID` TEXT(6) NOT NULL,
`Name` VARCHAR(45) NULL,
`Email` VARCHAR(254) NULL,
`Password` VARCHAR(45) NULL,
PRIMARY KEY (`StaffID`),
CONSTRAINT `StaffID`
FOREIGN KEY ()
REFERENCES `ApplicationSystem`.`UserType` ()
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
MySQL said: Documentation
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')
REFERENCES `ApplicationSystem`.`UserType` ()
ON DELETE NO ACTION
' at line 8
这里是实际的 SQL 代码:
-- MySQL Script generated by MySQL Workbench
-- 04/04/16 23:56:12
-- Model: New Model Version: 1.0
-- MySQL Workbench Forward Engineering
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';
-- -----------------------------------------------------
-- Schema ApplicationSystem
-- -----------------------------------------------------
-- -----------------------------------------------------
-- Schema ApplicationSystem
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `ApplicationSystem` DEFAULT CHARACTER SET utf8 ;
USE `ApplicationSystem` ;
-- -----------------------------------------------------
-- Table `ApplicationSystem`.`staff`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `ApplicationSystem`.`staff` (
`StaffID` TEXT(6) NOT NULL,
`Name` VARCHAR(45) NULL,
`Email` VARCHAR(254) NULL,
`Password` VARCHAR(45) NULL,
PRIMARY KEY (`StaffID`),
CONSTRAINT `StaffID`
FOREIGN KEY ()
REFERENCES `ApplicationSystem`.`UserType` ()
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `ApplicationSystem`.`UserType`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `ApplicationSystem`.`UserType` (
`Type` ENUM('A', 'HA', 'AT') NULL,
`ID` TEXT(6) NOT NULL,
INDEX `ID_idx` (`ID` ASC),
PRIMARY KEY (`ID`),
UNIQUE INDEX `ID_UNIQUE` (`ID` ASC),
CONSTRAINT `ID`
FOREIGN KEY (`ID`)
REFERENCES `ApplicationSystem`.`Applicants` (`ApplicantID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `ID`
FOREIGN KEY (`ID`)
REFERENCES `ApplicationSystem`.`staff` (`StaffID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `ApplicationSystem`.`Applicants`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `ApplicationSystem`.`Applicants` (
`ApplicantID` TEXT(6) NULL,
`Firstname` VARCHAR(40) NULL,
`surname` VARCHAR(40) NULL,
`DOB` DATE NULL,
`Gender` ENUM('yes', 'no') NULL,
`Address` VARCHAR(45) NULL,
`Postcode` VARCHAR(9) NULL,
`ApplicantMobile` TEXT(11) NULL,
`ApplicantHome` TEXT(11) NULL,
`ApplicantEmail` VARCHAR(255) NULL,
`ParentName` VARCHAR(40) NULL,
`Relationtoapplicant` VARCHAR(15) NULL,
`ParentEmail` VARCHAR(255) NULL,
`ParentAddress` VARCHAR(40) NULL,
`ParentPostcode` VARCHAR(9) NULL,
`ParentHome` TEXT(11) NULL,
`ParentMobile` TEXT(11) NULL,
`Currentschool` VARCHAR(40) NULL,
`ApplicantInYr11` ENUM('yes', 'no') NULL,
`Sibbling` ENUM('yes', 'no') NULL,
`SibblingName` VARCHAR(40) NULL,
`SibblingYear` TEXT(2) NULL,
`MedicalConditions` VARCHAR(30) NULL,
`AccessArrangementsAvailable` ENUM('yes', 'no') NULL,
`AccessArrangments` VARCHAR(20) NULL,
`Ethnic` VARCHAR(40) NULL,
`FirstLanguage` VARCHAR(15) NULL,
`HomeLanguage` VARCHAR(15) NULL,
`Religion` VARCHAR(15) NULL,
`Nationality` VARCHAR(20) NULL,
`ArmedForces` ENUM('yes', 'no') NULL,
`PreviouslyLookedAfter` ENUM('yes', 'no') NULL,
`EUResident` ENUM('yes', 'no') NULL,
`RestrictionResidence` ENUM('yes', 'no') NULL,
`school1` VARCHAR(45) NULL,
`school2` VARCHAR(45) NULL,
`school3` VARCHAR(45) NULL,
`school4` VARCHAR(45) NULL,
`UPN` TEXT(13) NULL,
`UCL` TEXT(13) NULL,
`ULN` TEXT(10) NULL,
`Password` VARCHAR(40) NULL,
`Course1` VARCHAR(30) NULL,
`Course2` VARCHAR(30) NULL,
`Course3` VARCHAR(30) NULL,
`Course4` VARCHAR(30) NULL,
`Course5` VARCHAR(30) NULL,
`Complete` TINYINT(1) NULL,
`Outcome` ENUM('R', 'A') NULL,
PRIMARY KEY (`ApplicantID`),
UNIQUE INDEX `idtable1_UNIQUE` (`ApplicantID` ASC),
UNIQUE INDEX `ApplicantEmail_UNIQUE` (`ApplicantEmail` ASC),
CONSTRAINT `ApplicantID`
FOREIGN KEY ()
REFERENCES `ApplicationSystem`.`UserType` ()
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `ApplicationSystem`.`table1`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `ApplicationSystem`.`table1` (
`ID` TEXT(6) NOT NULL,
`outcome` TEXT(6) NULL,
PRIMARY KEY (`ID`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `ApplicationSystem`.`outcome`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `ApplicationSystem`.`outcome` (
`ID` TEXT(6) NOT NULL,
`Outcome` ENUM('R', 'A') NULL,
PRIMARY KEY (`ID`),
CONSTRAINT `ID`
FOREIGN KEY (`ID`)
REFERENCES `ApplicationSystem`.`Applicants` (`ApplicantID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
USE `ApplicationSystem` ;
-- -----------------------------------------------------
-- Placeholder table for view `ApplicationSystem`.`view1`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `ApplicationSystem`.`view1` (`id` INT);
-- -----------------------------------------------------
-- View `ApplicationSystem`.`view1`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `ApplicationSystem`.`view1`;
USE `ApplicationSystem`;
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS
FOREIGN KEY (`here shoud be the column name the key belongs to`)
CONSTRAINT `StaffID`
FOREIGN KEY ()
REFERENCES `ApplicationSystem`.`UserType` ()
要声明外键约束,您必须指明参与约束的具体列。你在这里没有这样做。正确的语法是
CONSTRAINT `StaffID`
FOREIGN KEY (<name of a column in this table>)
REFERENCES `ApplicationSystem`.`UserType` (<name of the matching column in the referenced table>)
用正确的实际列名填写<placeholders>
。
不过,塞巴斯说得有道理;数据不是 "in" 或 Workbench 或 phpMyAdmin;这些只是连接到数据库进程的管理客户端,因此您应该能够建立到现有数据库的新连接。