Subject | Re: [firebird-support] What is better? use integrity referencial or triggers? |
---|---|
Author | Jerome Bouvattier |
Post date | 2003-11-27T10:04:03Z |
Hi,
triggers" unlike the subject is saying.
I suggest you read it along with the article "Declarative referential
integrity vs triggers" from Claudio Valderama.
http://www.cvalde.net/document/declaRefIntegVsTrig.htm
Basically, you can safely use RI triggers to check record existence in
so-called static tables in which you never delete records. Provided the
referenced table has few values, you might even gain in performance, because
you will avoid a low selectivity index in the referencing table.
In other cases, you probably want to use decl. RI, because triggers won't
give the same level of integrity. It is just a question of time or luck
before your integrity gets broken. As you will learn in the mentionned
thread, this is due to fact that decl. RI and triggers run in different
transaction contexts.
check the thread...
If you ever gonna use triggers, you probably want to avoid count(*) wich
will kill your perf. Use EXITS instead :
if (new.PAIS_ID is not null) then
begin
if (not exists (select PAIS_ID
from PAISES
where PAISES.PAIS_ID = new.PAIS_ID)) then
begin
exception sdp_icpe;
end
end
Hope it helps.
--
Jerome
> for the check of the primary key, and the foreign key?, what isThis is exactly what targets the thread "Isolation level in CHECKs and
> better?, declare it trought constraints?, or do trought declare
> triggers that do the job?.
triggers" unlike the subject is saying.
I suggest you read it along with the article "Declarative referential
integrity vs triggers" from Claudio Valderama.
http://www.cvalde.net/document/declaRefIntegVsTrig.htm
Basically, you can safely use RI triggers to check record existence in
so-called static tables in which you never delete records. Provided the
referenced table has few values, you might even gain in performance, because
you will avoid a low selectivity index in the referencing table.
In other cases, you probably want to use decl. RI, because triggers won't
give the same level of integrity. It is just a question of time or luck
before your integrity gets broken. As you will learn in the mentionned
thread, this is due to fact that decl. RI and triggers run in different
transaction contexts.
> or.. if i have a foreign key? constraint?, with a constraint i can'tI'm in the same boat as you. I'm waiting for Ann's final word on this. So,
> specify the cardinality of the relation.
>
> the only way that i can check that is programing with triggers.
>
> It is fine?, or exist some recomendation?
check the thread...
If you ever gonna use triggers, you probably want to avoid count(*) wich
will kill your perf. Use EXITS instead :
if (new.PAIS_ID is not null) then
begin
if (not exists (select PAIS_ID
from PAISES
where PAISES.PAIS_ID = new.PAIS_ID)) then
begin
exception sdp_icpe;
end
end
Hope it helps.
--
Jerome