Prevent negative price
SQL
Easy
1 views
Problem Description
Stop INSERT and UPDATE if Products.price
Output Format
Trigger created
Constraints
MySQL-style SIGNAL for error
Official Solution
CREATE TRIGGER trg_products_price_ins BEFORE INSERT ON Products FOR EACH ROW BEGIN IF NEW.price <= 0 THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='Invalid price'; END IF; END; CREATE TRIGGER trg_products_price_upd BEFORE UPDATE ON Products FOR EACH ROW BEGIN IF NEW.price <= 0 THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='Invalid price'; END IF; END;
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!