How to create integrity constraints?

Let’s suppose I have an Instance: Invoice with Total 100 usd.
And I want to also insert the items of the invoice:
item A: 33usd
item B: 33usd
item C: 34usd…

So the constraint is that the Sum of the itemized items must be equal to the Invoice total.

And if the constraint fails, then the transaction should be cancelled.

Can you point me in the right direction.
Thank you.