Re: Help with using Triggers MySql/Innodb

Steven Lembark <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.dbi.general
Organization Workhorse Computing
Message-ID <[email protected]>
On Thu, 26 Feb 2015 15:31:56 +0000
"Martin J. Evans" <[email protected]> wrote:

> I would actually suggest you don't use a trigger for this and also 
> that you don't store the count of people in a house in a column in 
> the house table. You can always calculate how many people there are 
> in a house but if you use triggers or some other mechanism to keep 
> the count you run the risk of the count not actually agreeing with 
> the rows with that house id. In other words, I think this is 
> generally bad design.

You could get a one-step summary using a view that does a select
with count(1) as "people" from a join of houses and people, grouped
by the house. That leaves the houses and people separate and still
gives you one-stop shopping for the houses with accurate counts.

-- 
Steven Lembark                                             3646 Flora Pl
Workhorse Computing                                   St Louis, MO 63110
[email protected]                                      +1 888 359 3508
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.