这个查询出了什么问题(多个更新表)

时间:2012-11-14 13:43:35

标签: sql sql-update

这实际上让我的phpmyadmin停止工作。

SET @admin_mail = "mail@mail.com";
--  5. SET ORDER MAIL

UPDATE 
sales_flat_order, 
sales_flat_order_address, 
-- sales_flat_order_status_history, 
sales_flat_quote, 
sales_flat_quote_address

SET 
sales_flat_order.customer_email = @admin_mail,
sales_flat_order_address.email = @admin_mail,
sales_flat_quote.customer_email = @admin_mail,
sales_flat_quote_address.email = @admin_mail;

1 个答案:

答案 0 :(得分:2)

您无法从一个语句更新多个表。您可以将多个表输入到单个SQL UPDATE语句中,如JOIN,但您实际上只能更新其中一个表中的值。

你必须这样做:

UPDATE 
 sales_flat_order
SET 
  sales_flat_order.customer_email = @admin_mail;

UPDATE
  sales_flat_order_address
SET
  sales_flat_order_address.email = @admin_mail;

等...

这是一个与此相关的好线程:How to update two tables in one statement in SQL Server 2005?