Where to validate a foreign key? [message #208641] |
Mon, 11 December 2006 11:38 ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
orate
Messages: 16 Registered: September 2005
|
Junior Member |
|
|
I have a base table block in which three of the items (a,b,c) are a foreign key.
Where to validate the foreign key?
- Only in the when-validate-record?
- or also in the when-validate-item on each one?
- When the last item is filled
(W-V-I on each one)
if :a is not null and :b is not null and :c is not null then
select count(*) into cnt
from T
where a = :a and b = :b and c = :c;
if cnt = 0 then
alert
raise form_trigger_failure?
end if;
end if;
- Immediately after fill any of the items
(W-V-I on :a)
if :a is not null then
select count(*) into cnt
from T
where a = :a
and (b = :b or :b is null)
and (c = :c or :c is null);
if cnt = 0 then
alert
raise form_trigger_failure?
end if;
end if;
And, in these cases, make the trigger fail in order to force the user to correct that item? Or let the user to correct any of them?
|
|
|
Re: Where to validate a foreign key? [message #208679 is a reply to message #208641] |
Mon, 11 December 2006 21:28 ![Go to previous message Go to previous message](/forum/theme/orafaq/images/up.png) |
![](/forum/images/custom_avatars/67467.jpg) |
djmartin
Messages: 10181 Registered: March 2005 Location: Surges Bay TAS Australia
|
Senior Member Account Moderator |
|
|
You can let Oracle do it for you at the database level but using the three item validations and the record validation is the way that I have usually seen it done.
David
|
|
|