Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 FK integrity

Author  Topic 

Ex
Posting Yak Master

166 Posts

Posted - 2005-01-16 : 23:36:05
hey all

ok here is the latest problem

CREATE TRIGGER UPDATEGRADE ON GRADE
AFTER UPDATE
AS
UPDATE YIELD_STRESS_OFFSETS
SET GRADE = i.GRADE
FROM YIELD_STRESS_OFFSETS y,inserted i, deleted d
WHERE y.GRADE = d.GRADE AND i.GID = d.GID


Grade PK (GRADE )
GID is a identity Column i added for simplicitiy on joins as "they" update the pk value :(

YIELD_STRESS_OFFSETS FK(GRADE) REFERENCES GRADE(grade)

i know this is a messy table hehe but i didnt design the buggar

just wondering how can i do the update here without stuffing the refence integrity if i update grade first then
YIELD_STRESS_OFFSETS wont see the grade and throw a FK excpetion
and if update YIELD_STRESS_OFFSETS the grade wont be in GRADE and a FK exception will be thrown


the only way i can think of doing this is do a instead of update trigger like so

CREATE TRIGGER UPDATEGRADE ON GRADE
INSTEAD OF UPDATE
AS

insert into grade(GRADE,DESCRIPTION,GRADEFACTOR,GROUPNAME)
select GRADE,DESCRIPTION,GRADEFACTOR,GROUPNAME from inserted


UPDATE YIELD_STRESS_OFFSETS
SET GRADE = i.GRADE
FROM YIELD_STRESS_OFFSETS y,inserted i, deleted d
WHERE y.GRADE = d.GRADE AND i.GID = d.GID



delete from GRADE where grade in (select grade from deleted)




is there a better way to do it?

clarkbaker1964
Constraint Violating Yak Guru

428 Posts

Posted - 2005-01-18 : 19:37:32
What about creating the foreign key constraint with nocheck?

Go to Top of Page

Ex
Posting Yak Master

166 Posts

Posted - 2005-01-18 : 19:44:53
ah its all good got it worked out do insert/delete combo when they change the pk :) otherwise normal update thanks anyways
Go to Top of Page
   

- Advertisement -