-2

任何想法为什么我不能创建 Clinical_QUestions 表?

CREATE  TABLE IF NOT EXISTS `test`.`Questions` (
`QuestionID` INT NOT NULL ,
`Question` VARCHAR(45) NULL ,
`VersionNumber` INT NULL ,
`Core` TINYINT(1) NULL ,
PRIMARY KEY (`QuestionID`) )
ENGINE = InnoDB;    

我无法创建此表

CREATE  TABLE IF NOT EXISTS `test`.`Clinical_Questions` (
`ClinicalID` INT NOT NULL ,
`QuestionID` INT NULL ,
`Effective Week` INT NULL ,
PRIMARY KEY (`ClinicalID`) ,
INDEX `QuestionID_idx` (`QuestionID` ASC) ,
CONSTRAINT `QuestionID`
FOREIGN KEY (`QuestionID` )
REFERENCES `test`.`Questions` (`QuestionID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `ClinicalID`
FOREIGN KEY (`ClinicalID` )
REFERENCES `test`.`Clinical` (`ClinicalID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;

错误 1005 (HY000): 无法创建表 'certestdb.Clinical_Questions' (errno: 121)

CREATE  TABLE IF NOT EXISTS `test`.`Overall_Week_Rating` (
`ClinicalID` INT NOT NULL ,
`Instructor_Rating` INT NULL ,
`DateTime_Instructor_Rating` DATETIME NULL ,
`Student_Rating` INT NULL ,
`DateTime_Student_Rating` DATETIME NULL ,
PRIMARY KEY (`ClinicalID`) ,
CONSTRAINT `UserID`
FOREIGN KEY (`ClinicalID` )
REFERENCES `test`.`Clinical` (`ClinicalID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
4

1 回答 1

2

您在CREATE TABLE声明中某处的声明中有错误 if INDEX。您应该ASC从索引部分中删除。

INDEX `Section_idx` (`Question_Section`)

将出现的第二个问题是您没有在FOREIGN KEY约束上定义键,

CONSTRAINT cons_EffectiveDate
    FOREIGN KEY (`Effective Date`)                -- add column name
    REFERENCES `certestdb`.`Section` (columnHere) -- add also column name
    ON DELETE NO ACTION
    ON UPDATE NO ACTION
于 2013-04-06T04:02:38.240 回答