Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: can a field reference the sum of a field in another table?
"kaeli" <tiny_one_at_NOSPAM.comcast.net> wrote in message
news:MPG.1b7404a02a6d994198a009_at_nntp.lucent.com...
|
| Hey all,
|
| I'd like to make a table with a field that references the sum of another
| field in another table. I know I could use a view for this, but it would
be
| more convenient if I could do it right in the table. Is that possible?
|
| Example:
| create table tblAttendees (
| name varchar2(50) primary key,
| regDate date,
| seminarId integer references tblSeminars);
|
| create table tblSeminars (
| seminarId integer primary key,
| seminarName varchar2(50),
| maxAttendees integer,
| numAttendees integer)
|
| I'd like tblSeminars.numAttendees to be
| select count(*) from tblAttendees where
| tblAttendees.seminarId=tblSeminars.seminarId
|
| Can I do that in the table, or do I need to use a view?
| Using Oracle 8i on Solaris.
|
| TIA
|
| --
| --
| ~kaeli~
| Do not taunt Happy Fun Ball!
| http://www.ipwebdesign.net/wildAtHeart
| http://www.ipwebdesign.net/kaelisSpace
|
you need to use a view or else use a trigger on the tblAttendees table that would maintain the derived value in numAttendees
perhaps, while we're waiting for Sybrand to elaborate on the theological implications of denormalization, you could elaborate on why it would be more convenient to have the derived value in the table rather than to create a view that derives the value?
![]() |
![]() |