Subject Re: Is using SELECT COUNT (*) in a stored procedure a bad idea? (Once Again)
Author Alexander V.Nevsky
--- In firebird-support@yahoogroups.com, "M Tuttle" <miket@s...>
wrote:
> I assume I can still ask Interbase OS questions here, right?

Of course. Subj - absolutly bad idea if CLIENT_SITE etc are not
static tables. Not count itself but it's usage.

> There is referentially Integrity with FK on all tables where
necessary..

If you have FKs on this tables - follow Martijn. If not - create
them.

> CREATE PROCEDURE SPS_DEBT_TYPE_SUB_CODE_DEL_CHK (
> V_DEBT_TYPE_SUB_CODE Char(3))
> returns (
> R_DELETE_OK SmallInt)
> AS
> DECLARE VARIABLE iRowCount INTEGER;
> BEGIN
> r_DELETE_OK = 0;
>
> /* See if we have a CLIENT_SITE record association on file */
> SELECT COUNT(*)
> FROM CLIENT_SITE CS
> WHERE CS.DEBT_TYPE_SUB_CODE = :v_DEBT_TYPE_SUB_CODE
> INTO :iRowCount;

And you got iRowCount=0.
At THIS moment another user, gloatingly smiling, inserted 100 rows
into CLIENT_SITE with DEBT_TYPE_SUB_CODE = :v_DEBT_TYPE_SUB_CODE.

Best regards,
Alexander.