gpt4 book ai didi

MySQL Workbench,不断出现错误 1064 错误

转载 作者:行者123 更新时间:2023-11-29 16:35:41 24 4
gpt4 key购买 nike

对于 SQL 来说还很陌生。尝试创建数据库,但一直遇到此问题?

在服务器中执行SQL脚本

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 'VISIBLE,

CONSTRAINT fk_Vurdering_Fag

FOREIGN KEY (Fag_Fagkode)

REF' at line 11

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条失败

以最终形式取回 View 定义。没有可获取的内容

有人知道可能出了什么问题吗?我已经在这里和其他地方重新研究了这个话题。这些解决方案都不适合我:(

任何提示将不胜感激,谢谢:)

最佳答案

All parts of a PRIMARY KEY must be NOT NULL; if you need NULL in a key, use UNIQUE instead

您已将属性 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;

关于MySQL Workbench,不断出现错误 1064 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53613574/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com