I need to add constraints to a particular field in all the entries of a child table with a foreign key to a single row in parent table. What is the best way to do it?
For example, my parent table has
Id Money Name
-- ----- ----
1 30 xyz
2 40 abc
And the table referencing this
Id Cost Person
-- ---- ------
1 10 1
2 10 1
3 20 2
Here Person is the foreign key and I need to put constraint in Cost based on Money, for instance, the sum of all cost should be always lesser or exactly equal to the total Money.