Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Triggers across tables

Re: Triggers across tables

From: mjc <cavett_at_globalnet.co.uk>
Date: 1997/04/27
Message-ID: <01bc52f0$b40534c0$LocalHost@cavett.globalnet.co.uk>#1/1

Lee Tuckman <ltuckman_at_wam.umd.edu> wrote in article <335E08E5.2F00_at_wam.umd.edu>...
> I am an Oracle beginner and I have been having problems implementing a
> trigger between two tables. My intention is to have the trigger fire
> when a new row is inserted into one table, take those values and add
> them to columns in another table in order to keep aggregate totals. I
> would really appreciate any suggestions on how I can implement this
> trigger across tables.
> Thanks,
> Lee
>

Try:

Definitions: Table1 : the non-aggragate table (child)

t1_id*		NUMBER	NOT NULL,		*primary key
t1_col1		NUMBER	,
t1_col2		NUMBER
t1_col3		NUMBER...	)

	      Table2 : the aggragate table (parent)

Note: there will (should) only ever be one row in this aggregate table in this senario!

t1_col1_tot	NUMBER,
t1_col2_tot	NUMBER,
t1_col3_tot	NUMBER...)

In a SQL session:

Thereafter rows will be updated in Table2 with new values from Table1 each time an insert is made into Table1. Have you thought about updates to Table1 and Delete's from Table1? Also, this could be made more generic. What you have here is a classic parent (Table2), child (Table1) relation, but since there is only 1 row in the parent table there is no foreign key relationships.

email me back if you like

-- 
	- Martyn Cavett
	  Senior ORACLE Analyst
	  LGT Asset Management
	  London, UK.
	  home: cavett_at_globalnet.co.uk
 	  work: Martyn.Cavett_at_gtplc.com

These views are my own and not those of my employer.  Normal conditions
apply.
Received on Sun Apr 27 1997 - 00:00:00 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US