每当我在其中运行此查询时,我都有一个名为broodjes-service
的数据库:
DELETE FROM order_items WHERE order_id = 42
我收到此错误:
#1146 Table 'broodjes-service.i' doesn't exist
虽然我确定这个表存在,但是这个表结构:
问题
我正在尝试从名为order_items
的表中删除一行,但由于某种原因它会占用表名i
。
问题
i
表格triggers
order_items
这个用于删除内容时:
UPDATE orders o
INNER JOIN (SELECT i.order_id id, SUM(i.quantity * p.price) total_price
FROM `orders-items` i
INNER JOIN products p ON p.id = i.products_id
AND i.order_id = old.order_id) t ON t.id = o.id
SET o.total_price = t.total_price
插入触发器
INNER JOIN (SELECT i.order_id id, SUM(i.quantity * p.price) total_price
FROM `orders-items` i
INNER JOIN products p ON p.id = i.products_id AND i.order_id = new.order_id) t ON t.id = o.id
SET o.total_price = t.total_price
更新触发器
UPDATE orders o INNER JOIN (SELECT i.order_id id, SUM(i.quantity * p.price) total_price FROM `orders-items` i INNER JOIN products p ON p.id = i.products_id AND i.order_id = new.order_id) t ON t.id = o.id SET o.total_price = t.total_price
答案 0 :(得分:0)
DELETE FROM `broodjes-service`.order_items
WHERE order_id = 42
如果你使用别名,那就像这样
DELETE i
FROM `broodjes-service`.order_items i
WHERE order_id = 42
不要混合数据库名称和别名
DELETE `broodjes-service`.i
FROM `broodjes-service`.order_items i
WHERE order_id = 42
答案 1 :(得分:-1)
尝试:
Use broodjes-service;
DELETE FROM order_items WHERE order_id = 42