Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What is the best way to create a trigger?

Status
Not open for further replies.

bombplayer

Programmer
Jul 3, 2001
47
0
0
US
I have three tables tbl_Students, tbl_Enrolled and tbl_Classes. The tbl_Students and tbl_Enrolled have a one to one relationship. When a student is enrolled in a class in tbl_Classes, the ClassID field is placed in tbl_Enrolled to create a join between tbl_Enrolled and tbl_Classes.

I am trying to create a trigger to tell me when the ClassID field is updated in tbl_Enrolled but my problem is that I don't want all of the updates. I only want to fire the trigger when the class start time field of tbl_Classes equals say 8 a.m.

Maybe my thinking on this is backwards or something but how can I create a trigger on the tbl_Enrolled table when I am referencing another table?
 
you could use an if statement in the trigger to catch changes to certain fields and update the relevant table with the contents of inserted an deleted pseudo tables.

example of IF I was thinking of:
Code:
CREATE TRIGGER trig1 ON your yourtable FOR INSERT UPDATE etc...
as 
IF --your condition i.e. start time = 8am
BEGIN
UPDATE/INSERT INTO yourupdate table
--results from inserted/deleted tables
END
GO

[bandito] [blue]DBomrrsm[/blue] [bandito]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top