I am trying to create Update trigger which should be invoked only if the ReturnedOn column is clicked.
I have used the following code-snippet but it generates the error:
CODING:
CREATE TRIGGER trg_ForUpdateOnBookIssuedDetails
on BOOKISSUEDDETAILS
For update
as
begin
declare @Rows1 int,@Rows2 int
if(update(ReturnedOn)
begin
IF EXISTS(SELECT 1 FROM INSERTED)
begin
update nur
set nur.NumberOfBooksIssued = nur.NumberOfBooksIssued -1
from NewUserRegister nur inner join INSERTED i
on i.IssuedTo=nur.UserName
set @Rows1 = @@RowCount
update lbd set Inventory = Inventory +1
from LIBRARYBOOKDETAILS lbd inner join inserted i
on lbd.BookID = i.BookId
set @Rows2 = @@rowcount
if @Rows1 * @rows2 >0
commit tran
else
begin
raiserror('Error Updating the Database',16,-1)
rollback tran
end
end
end
end
ERROR STATEMENT:
Msg 156, Level 15, State 1, Procedure trg_ForUpdateOnBookIssuedDetails, Line 9 Incorrect syntax near the keyword 'begin'.
I want the trigger to be fired only if the ReturnedOn column is updated, however if anyother column is updated the trigger should not be fired.
Can anyone help me identify the error and changes I should make to rectify this error?
Thanks in advance!!