gpt4 book ai didi

mysql - 将新列作为外键添加到表中

转载 作者:行者123 更新时间:2023-11-30 22:34:27 25 4
gpt4 key购买 nike

我很难尝试向我的 sql 表中添加一个列,该列将成为另一个表的外键。我收到以下错误:

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 ''description_id' INT,
ADD FOREIGN KEY (description_id)
REFERENCES description(de' at line 2

来 self 的查询:

ALTER TABLE images
ADD COLUMN 'description_id' INT,
ADD FOREIGN KEY (description_id)
REFERENCES description(description_id)

这是我的表,我正在尝试将列添加到:

CREATE TABLE `images` (
`id` int(5) NOT NULL AUTO_INCREMENT,
`pattern` varchar(225) DEFAULT NULL,
`color` varchar(225) DEFAULT NULL,
`imageUrl` varchar(225) DEFAULT NULL,
`imageSource` varchar(225) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=47 DEFAULT CHARSET=latin1;

这是正在连接的表:

CREATE TABLE `description` (
`description_id` int(11) NOT NULL,
`color` varchar(255) DEFAULT NULL,
`pattern` varchar(255) DEFAULT NULL,
`body` varchar(255) DEFAULT NULL,
PRIMARY KEY (`description_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

最佳答案

您不能更改表添加,添加。尝试:

ALTER TABLE images
ADD COLUMN 'description_id' INT
REFERENCES description(description_id)

关于mysql - 将新列作为外键添加到表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33004779/

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