我有一个问题,我执行了一个对数据库中的几个表进行更新的存储过程。错误是这样完成的,每次只有一个字段(表示相同的记录 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