我遇到了一个问题,我执行了一个存储过程,对数据库中的几个表进行了更新。完成该错误使得每次仅将单个字段(表示相同的记录id)更新为新的id。这是spoc:
DROP PROCEDURE IF EXISTS feeds_transfer;
DELIMITER $$
CREATE PROCEDURE feeds_transfer(IN original_owner INT, IN new_owner INT, IN feed_id INT)
BEGIN
UPDATE `events` SET `user_id` = new_owner WHERE `user_id` = original_owner AND `feed_id` = feed_id;
UPDATE `feeds` SET `partner_id` = new_owner WHERE `partner_id` = original_owner AND `id` = feed_id;
UPDATE `ics_uploads` SET `user_id` = new_owner WHERE `user_id` = original_owner AND `context_type` = 'feed' AND `context_id` = feed_id;
UPDATE `images` SET `user_id` = new_owner WHERE `user_id` = original_owner AND `context` = 'feed' AND `context_id` = feed_id;
UPDATE `private_feed_invitees` SET `user_id` = new_owner WHERE `user_id` = original_owner AND `feed_id` = feed_id;
UPDATE `subscribed_feeds` SET `user_id` = new_owner WHERE `user_id` = original_owner AND `feed_id` = feed_id;
END $$
DELIMITER ;
subscribed_feeds表将更新user_id = original_owner的每条记录。就像忽略feed_id
= feed_id
答案 0 :(得分:1)
好的,所以这里发生的事情并不是忽略feed_id
= feed_id子句,它始终是真的,所以它总是会触发比希望更多的更新。这个故事的寓意是,你永远不应该将存储过程的输入变量命名为与计划进行逻辑检查的任何字段相同的内容。