【发布时间】:2021-03-14 05:45:34
【问题描述】:
如果用户尝试在订单中插入的数量大于可用数量,我想创建一个引发错误的触发器或存储过程。
所以基本上,我有 2 个表:Order_Product 具有 OrderId、Product_Id 和 Quantity,以及 Inventory 具有 Product_Id 和 Quantity。因此,如果用户尝试在 Order_Product 中为特定 product_id 插入数量大于 Inventory 中相同 product_id 可用数量的行,则在插入之前抛出错误。
提前谢谢你。
【问题讨论】:
-
如果用户尝试在 Order_Product 中为特定 product_id 插入一行,其数量大于 Inventory 中相同 product_id 的可用数量 用户是否可以插入 2 行哪个单独匹配但总和超大?这合法吗?
标签: mysql sql stored-procedures triggers sql-insert