0
I wrote my first trigger and it giving error 

     UES TRY
        GO
        CREATE TRIGGER cust_update
        ON TRY
        FOR UPDATE
        AS
            IF UPDATE (custno)
            BEGIN TRANSACTION
            RAISERROR('CUST NO CANNOT BE UPDATED',10,1)
            ROLLBACK TRANSACTION
            END



Any idea


`
3
Contributors
2
Replies
22
Views
3 Years
Discussion Span
Last Post by ryanjayson
0

Im gonna toss my 2cents out, and with fair warning Im not 100% sure, as I don't tend to handle the triggers for our DB, but as any good soldier, Im aware of them and my understand of how they work. :-/

I believe you should set the trigger on the field you are "snooping" as follows:

USE TRY
GO
CREATE TRIGGER cust_update
ON
TRY.custno
FOR UPDATE
AS
RAISEERROR('CUST NO CANNOT BE UPDATED',10,1)
GO

I believe that this should short circuit the update on custno, raise the error, and prevent the update. The trigger for rollback would require that a transaction actually be created explicitly... However, my knowledge and experience in that regard is limited (in fact, it's non-existent, as I have never used a trigger in this fashion).

If the above doesn't work, I appologize. However, I believe it will do what you are attempting to do.

Good luck,

Ryan

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.