Subject Re: [firebird-support] Recordcount
Author Mark Rotteveel
> To avoid SELECT COUNT(*) FROM....., I made a table that keeps track of the
> recordcount of big tables.
>
> TBL_RECORDCOUNT (
> RCC_TABLE VARCHAR(31) NN PK,
> RCC_COUNT INTEGER NN)
>
> Then I use After Insert / After Delete triggers to do a Count + 1 or Count
> - 1.
> Now I'm wondering : What if 2 users insert a customer record exactly the
> same time (I know this might not be the case), but it's just a "what if"
> scenario. The After Insert trigger of the Customer table will be fired and 2
> simultanous updates will happen on TBL_RECORDCOUNT. I'm wondering what
> will happen ? A deadlock ? And perhaps the Field RCC_COUNT will no longer
> hold the correct value ?

It might be simpler to have the trigger insert a +1 or -1 into the table and then do a SUM(RCC_COUNT). Nightly or weekly or so you can then rebuild the content of the table (so every table has only one record again).

Mark
--
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01