I am working on MARIADB terminal. I have a task to write query that deducts the quantity of a product by 5, before it updates, it needs to check that we have sufficient amount of quantity. If the quantity goes below 0 then we dont want to udpate, instead, we would like to throw an error.
This is not a pl/sql or procedure. Just a query that we can execute directly on terminal/mysql shell
Query written so far:
Update inventory
SET
quantity_in_stock =
IF(((SELECT quantity_in_stock from inventory WHERE product_id = 101)-5) >= 0,
((SELECT quantity_in_stock from inventory where product_id =101)-5),
()
where product_id = 101;
I want to raise ERROR in the () section (2nd last line of query).
SQL-MARIADB statement to raise/generate an error in () section of update query.