Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Update trigger - why it works?
Message
 
 
À
Tous
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
Update trigger - why it works?
Versions des environnements
SQL Server:
SQL Server 2005
Divers
Thread ID:
01291246
Message ID:
01291246
Vues:
52
Hi everybody,

I wrote the following trigger that updates the table itself among other tasks. Suprisingly it works and doesn't go into the infinite loop. Can someone please explain how does it work?
create trigger SR_tr_UPDATE on Student_Registration after update 
as
  begin
     declare @Status char(1)
     select @Status = Status from Inserted
     if @Status = 'D'
        begin  
        update Student_Registration set Drop_Date = getdate() 
        from Student_Registration SR, Inserted I 
        where SR.SID = I.SID and SR.TermID = I.TermID

        update Student_Summary set NumOfCourses = NumOfCourses - 1
        from Student_Summary SS inner join Inserted I on 
        SS.SID = I.SID

        update Course_Summary set NumberOfStudents = NumberOfStudents - 1
        from Inserted I, Course_Term CT, Course_Summary CS 
        where  I.TermID = CT.TermID and (CS.cYear = CT.cYear and CS.cID = CT.cID)
       end
   else
    begin
      print 'Invalid Status'
      rollback tran
   end
end
Thanks a lot in advance.
If it's not broken, fix it until it is.


My Blog
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform