【发布时间】:2018-02-14 00:49:43
【问题描述】:
我有一个带有自动递增 id 的表。 id 也是另一个表中的外键。当我尝试向这些表中添加值时,出现异常 - 列数与第 1 行的值计数不匹配
这些是我的桌子:
CREATE TABLE Hotspot(
num int auto_increment not null,
id varchar(255),
x int,
y int,
width int,
height int,
UNIQUE(id),
PRIMARY KEY (num)
);
CREATE TABLE Hotspot_Label(
num int auto_increment not null,
question_id varchar(255),
hotspot_id varchar(255),
label_id varchar(255),
PRIMARY KEY (num),
FOREIGN KEY (hotspot_id)
REFERENCES Hotspot(id),
FOREIGN KEY (label_id)
REFERENCES Label(id),
FOREIGN KEY (question_id)
REFERENCES Question(id)
);
这是其中一张表的存储过程
PROCEDURE `insertHotspot`(IN recID varchar(255), x int, y int, width int, height int)
BEGIN
INSERT INTO Hotspot VALUES(recID, x, y, width, height);
END
我已经读到您不需要在存储过程中插入自动增量值,所以我看不到出了什么问题
【问题讨论】:
-
这是我认为在 INSERT 上省略表名后的可选字段列表的众多原因之一。
标签: mysql stored-procedures auto-increment