Oto jak możesz to zrobić w MySQL (Twoje pytanie jest oznaczone tagami mysql
i sql-server
)
CREATE TRIGGER tg_bi_order_contains_items
BEFORE INSERT ON Order_contains_items
FOR EACH ROW
SET NEW.Ordered_price =
(
SELECT Unit_price * NEW.Quantity_ordered
FROM Item
WHERE Item_id = NEW.Item_id
LIMIT 1
);
CREATE TRIGGER tg_bu_order_contains_items
BEFORE UPDATE ON Order_contains_items
FOR EACH ROW
SET NEW.Ordered_price =
(
SELECT Unit_price * NEW.Quantity_ordered
FROM Item
WHERE Item_id = NEW.Item_id
LIMIT 1
);
Oto SQLFiddle demo