我有以下表格:Persons,Person_Categories和Persons_PersonCategories,它们是n:m关系的链接表。
我还编写了以下查询,但insert语句无法正常工作。插入,更新和删除是单独的语句。我得到的错误消息是“列数与第1行的值计数不匹配”
SELECT Persons_PersonCategories.PersonID, PrsCategory
FROM Person_Categories
INNER JOIN Persons_PersonCategories
ON Persons_PersonCategories.PrsCatID = Person_Categories.PrsCatID
INSERT INTO Persons_PersonCategories
VALUES (:PrsCategory)
UPDATE Persons_PersonCategories
SET Persons_PersonCategories.PrsCatID = :PrsCatID
WHERE Person_Categories.PrsCatID = :OLD PrsCatID
AND Persons.PersonID = :OLD PersonID
DELETE FROM Persons_PersonCategories
WHERE Person_Categories.PrsCatID = :PrsCatID
AND Persons.PersonID = :PersonID;
任何帮助将不胜感激, 咱
答案 0 :(得分:1)
指定要更新的列:
INSERT INTO Persons_PersonCategories (PrsCategory) VALUES (:PrsCategory)
如果我没有正确猜到你正在尝试做什么,请用正确的列名代替PrsCategory
。
答案 1 :(得分:0)
看起来您需要添加PersonID
INSERT INTO Persons_PersonCategories(PersonID, PrsCatID)
VALUES (:PersonID, :PrsCatID)