Hi all,
can anybody explain me the below code for trigger?Please note that the above code was written by one of my class mate and I cannot understand anything in it.
I am not able to understand it.
Also if there is any other way to accomplish the same task then please let me know.
CREATE trigger [dbo].[trg_InsertInBookIssuedDetails]
on [dbo].[BOOKISSUEDDETAILS]
for insert
as
begin
begin tran
update nur
set nur.NumberOfBooksIssued = nur.NumberOfBooksIssued+1
FROM NEWMEMBER nur
INNER JOIN INSERTED i
ON i.IssuedTo = nur.MEMBERName
if exists(
select 1
from LIBRARYBOOKDETAILS lbd
INNER JOIN INSERTED i
ON i.BookID = lbd.BookID
WHERE lbd.Inventory<=1
)
begin
raiserror('Books UnAvailable Or Cannot Issue More Than 3 Books',16,-1)
rollback tran
end
else
begin
update lbd
set lbd.Inventory = lbd.Inventory - 1
FROM LIBRARYBOOKDETAILS lbd
INNER JOIN INSERTED i
ON lbd.BookID= i.BookID
commit tran
end
end
Please help me out in understanding the above trigger statement.
Thanks in advance!