Anyone know anything about Oracle? I'm completely lost here.

Status
Not open for further replies.
Alright, I have two tables and a view- for all intensive purposes, this is what the tables looks like:

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.
 
Just create a trigger. I don't remember the exact syntax but you will want it something like this

create trigger <name>

on update, insert, delete

Have it check the table

then the tables that need to be updated and from where

Do a search on google for syntax. Sorry i can't be more clear and i just wrote a trigger for work yesterday lol.
 
iyox said:
Just create a trigger. I don't remember the exact syntax but you will want it something like this

create trigger <name>

on update, insert, delete

Have it check the table

then the tables that need to be updated and from where

Do a search on google for syntax. Sorry i can't be more clear and i just wrote a trigger for work yesterday lol.

The problem is I don't know how to make the trigger for one table check for a specific value in another table.
 
Status
Not open for further replies.
Top Bottom