Sell Only What's in Stock
MediumDescription
Create a procedure pr_sell with two parameters, a product id and a quantity, in that order.
- If the product's
stockcovers the quantity, the stock goes down by the quantity. A product whose stock reaches 0 also becomes unavailable (is_availablebecomes false). - If there isn't enough stock, nothing changes, and there is no error.
Then finish with exactly these statements:
CodeCALL pr_sell(26, 30); CALL pr_sell(26, 30); CALL pr_sell(14, 35); SELECT product_id, stock, is_available FROM products WHERE product_id IN (14, 26) ORDER BY product_id;
Tables
| products |
|---|
| product_id (PK) |
| product_name |
| stock |
| is_available |