Skip to main content
Admissions guidance, study banks, and career tools — get started on Shalyam

Trigger to Prevent Negative Stock

Create a trigger that rejects any update that would make Stock.qty negative.

Table schema

Stock(product VARCHAR(20) PRIMARY KEY, qty INT)

Sample data

Row (Pen, 5). UPDATE Stock SET qty = qty - 8 WHERE product = 'Pen'; must fail.

Discussion

No discussions yet.

Rewards · v2.1

Get Exclusive Insights with Every Issue

Join Shalyam Newsletter

Stay ahead in education, research, and innovation—straight to your inbox.