Donaldino Donaldino - 1 year ago 60
MySQL Question

Unsure whether to use a Trigger or Procedure in SQL project

This is my example relation that I am working with named 'Balance Sheet' with 4 attributes.

Balance Sheet

| companyTicker | assets | liabilities | equity |

If someone adds a tuple to this relation where
(assets != liabilities + equity)
I would like either an error to be thrown saying that the data is invalid, or for the tuple to simply not be added. Should i use a procedure or something like a "before Update" trigger for this?

Answer Source

Checkout this answer SQL Differences between stored procedure and triggers by @Bohemian. Since the check is to be performed at the time of insertion or when updating, go with triggers.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download