Mister Zimbu
Member
Alright, I have two tables and a view- for all intensive purposes, this is what the tables looks like:
Basically, getsMoney is a table of all transactions in which my person gets money, and spendsMoney is a table of all transactions in which a person spends money, and the view contains the amount of money the person has left.
My problem is this- how would I go about making a constraint/trigger/check that would prevent a new entry from being added to spendsMoney if that would cause his total funds to go below zero? I know some basic things about checks and triggers but have no idea on how to use them to check OTHER tables' values.
Thanks.
Code:
create table getsMoney (
money number
);
create table spendsMoney (
money number
);
create view funds as
select decode( getSum, NULL, 0, getSum ) - decode( spendSum, NULL, 0, spendSum ) AS cash
from
(select sum( getsMoney.money ) AS getSum FROM getsMoney),
(select sum( spendsMoney.money ) AS spendSum FROM spendsMoney);
Basically, getsMoney is a table of all transactions in which my person gets money, and spendsMoney is a table of all transactions in which a person spends money, and the view contains the amount of money the person has left.
My problem is this- how would I go about making a constraint/trigger/check that would prevent a new entry from being added to spendsMoney if that would cause his total funds to go below zero? I know some basic things about checks and triggers but have no idea on how to use them to check OTHER tables' values.
Thanks.