Before insert trigger to clean data

Easy
1 views 23 Jan 2026
In Customers, automatically trim and lowercase email before insert....

After insert audit trigger

Easy
0 views 23 Jan 2026
After inserting into Orders, insert a row into AuditLog(table_name, row_id, action)....

Prevent negative price

Easy
0 views 23 Jan 2026
Stop INSERT and UPDATE if Products.price ...

Auto-update updated_at column

Easy
1 views 23 Jan 2026
On update of Orders, set updated_at to current timestamp automatically....

Maintain stock on order item insert

Easy
0 views 23 Jan 2026
When a new OrderItems row is inserted, decrement Inventory.qty....

Prevent deleting paid orders

Medium
0 views 23 Jan 2026
Block deleting an order if any payment exists for that order. Use a BEFORE DELETE trigger on Orders and check Payments....

Audit updates with old and new values

Medium
0 views 23 Jan 2026
On Employees salary update, insert into SalaryAudit(emp_id, old_salary, new_salary, changed_at)....

Auto-create customer code

Medium
0 views 23 Jan 2026
Customers(customer_id, code). On insert, if code is null, set it as 'C' + customer_id....

Keep summary table in sync

Medium
0 views 23 Jan 2026
Maintain DailySales(day, amount). After insert into Orders, update DailySales for that date....

Stop duplicate active coupon

Medium
0 views 23 Jan 2026
Coupons(code, is_active). Before INSERT, if the same code already exists with is_active=1, then block the insert....

Complex trigger with transaction-safe stock check

Hard
0 views 23 Jan 2026
Before inserting OrderItems, ensure Inventory has enough qty for that product. If stock is not enough, raise an error to stop the insert....

Handle update of qty in order items

Hard
0 views 23 Jan 2026
On update of OrderItems.qty, adjust Inventory by the difference....

Prevent salary decrease beyond 20%

Hard
1 views 23 Jan 2026
Before updating Employees.salary, block the update if the new salary is less than 80% of the old salary....

Soft delete via trigger

Hard
0 views 23 Jan 2026
Instead of physically deleting a customer, do a soft delete: set is_active=0 and stop the DELETE. Use a BEFORE DELETE trigger to enforce this rule....

Archive deleted rows using trigger

Hard
0 views 23 Jan 2026
When a customer row is deleted, copy it into DeletedCustomers(customer_id, name, deleted_at) before deletion....