Originally posted by: paul.brett
Further details on this issue....
The foreign key relationship is implemented as a trigger. When data is inserted into certain tables, the trigger runs, and checks that the inserted data meets the 'foreign key' criteria, and if not, triggers an exception and a transaction roll-back.
Example:
create trigger TRIGGER1
on TABLE1
for insert
as
declare @rows int
select @rows = @@rowcount
if @rows = 0 return
if ( select count(*) from inserted
where
isnull(ref_group_cd ,null) is not null and
isnull(producer_cd ,null) is not null)
!=
( select count(*) from inserted , TABLE2 t1
where
inserted.ref_group_cd = t1.ref_group_cd
and inserted.producer_cd = t1.producer_cd)
begin
rollback transaction
raiserror 999999 "Foreign key insert (TABLE1) not permitted. Primary table: TABLE2"
return
end
go
Thank-you.
Paul.
Follow me on Twitter
#IBMSterlingTransformationExtender#IBM-Websphere-Transformation-Extender#DataExchange