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


`

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

What is the error?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.