dca
dca

Reputation: 31

Using trigger in one table and updating another table

CREATE TRIGGER dbo.updateTrigger
   ON  dbo.Education 
   AFTER UPDATE
   AS 
BEGIN
    SET NOCOUNT ON;
IF NOT (UPDATE( HighestDegreeDoc) OR UPDATE (GPA) OR UPDATE (CreditHours))
    RETURN
UPDATE dbo.School
set Uploaded =1
from dbo.School
JOIN inerted i ON i.Uploaded = School.Uploaded
END
GO

What is Wrong with this code. i am trying to update field in School table , field uploaded when (HighestDegreeDoc , GPA, CrediHours) update in Education Table. NOTE Education Table has more than 15 field, (Uploaded Field in School table update only when these 3 field change)

Upvotes: 0

Views: 864

Answers (2)

George Mastros
George Mastros

Reputation: 24498

Just a guess....

JOIN inerted i ON i.Uploaded = School.Uploaded

Should be...

JOIN inserted i ON i.SchoolId = School.SchoolId

Looks like Updated is some sort of flag that you are setting. You probably want to join on an ID column instead.

Upvotes: 1

Xavinou
Xavinou

Reputation: 802

It's only a typo error : it's join inserted ;)

And I don't think your join condition is good.

Can you give us the ddl ?

Upvotes: 0

Related Questions