Anyone have a good example on how to use a trigger?
All I want is to update a field in a table (table a) depending on what value has been inserted in another a particular field in another table (table b).
Cheers, the book I've got here uses a "REFERENCES", but this doesn't seem to work under SQL2005, likewise SQL2000 has a BEFORE or AFTER clause, but 2005 assumes you're choosing a BEFORE unless you specifically say "AFTER".
OK well if anyone's interested, SQL2005 has a FANTASTIC feature called "INSTEAD OF" where you enter this after the creation of the trigger and put your code. Your code is then run INSTEAD OF what SQL server would normally do!
Brilliant!
Stupid example is:
Create Trigger NastyPasty ON Order.Items
INSTEAD OF
FOR INSERT
AS
BEGIN
DELETE * FROM Order.Items
END
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.