SQL新手。尝试创建数据库,但仍然遇到此问题?
在服务器中执行SQL脚本
错误:错误1064:您的SQL语法有错误;查看与您的MySQL服务器版本相对应的手册,以在“ VISIBLE”附近使用正确的语法,
约束
fk_Vurdering_Fag
外键(
第11行的Fag_Fagkode
)REF'
SQL代码:
-- -----------------------------------------------------
-- Table `Vurderingsbase`.`Vurdering`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `Vurderingsbase`.`Vurdering` (
`Vurderingsnr` INT NOT NULL AUTO_INCREMENT,
`Dato` DATETIME NOT NULL,
`Karakter` INT NULL,
`Type` VARCHAR(255) NULL,
`Fag_Fagkode` VARCHAR(255) NULL,
PRIMARY KEY (`Vurderingsnr`, `Fag_Fagkode`),
INDEX `fk_Vurdering_Fag_idx` (`Fag_Fagkode` ASC) VISIBLE,
CONSTRAINT `fk_Vurdering_Fag`
FOREIGN KEY (`Fag_Fagkode`)
REFERENCES `Vurderingsbase`.`Fag` (`Fagkode`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
SQL脚本执行完成:语句:成功6次,失败1次
以最终形式获取后视图定义。 什么都没拿
有人对可能出什么问题有想法吗?我已经在这里和其他地方重新提出了主题。没有一个解决方案对我有用:(
任何提示将不胜感激,谢谢:)
答案 0 :(得分:0)
PRIMARY KEY的所有部分都不能为NULL;如果您需要在NULL 键,请改用UNIQUE
您已将属性Fag_Fagkode
定义为NULL。将其更改为唯一。检查是否可行:
CREATE TABLE IF NOT EXISTS `Vurderingsbase`.`Vurdering` (
`Vurderingsnr` INT NOT NULL AUTO_INCREMENT,
`Dato` DATETIME NOT NULL,
`Karakter` INT NULL,
`Type` VARCHAR(255) NULL,
`Fag_Fagkode` VARCHAR(255) UNIQUE,
PRIMARY KEY (`Vurderingsnr`, `Fag_Fagkode`),
INDEX `fk_Vurdering_Fag_idx` (`Fag_Fagkode` ASC) ,
CONSTRAINT `fk_Vurdering_Fag`
FOREIGN KEY (`Fag_Fagkode`)
REFERENCES `Vurderingsbase`.`Fag` (`Fagkode`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
检查您的引用表列Fagkode
与以下数据类型相同:
CREATE TABLE IF NOT EXISTS `Vurderingsbase`.`Fag` (
`Fagkode` VARCHAR(255) UNIQUE PRIMARY KEY,
`Fag` VARCHAR(255) NULL NULL,
`Uketimer` INT NULL
)
ENGINE = InnoDB;