Click here to Skip to main content
15,913,722 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
create trigger salesdeletecsd on trnsalesdetails
for
delete
as
begin
update currentstockdetails set currentstock=currentstock + d.quantity from deleted d
join currentstockdetails sd on sd.itemcode=d.itemcode and sd.batchno=d.batchno
end


The above trigger update all items in the currentstock table during the sales entry is deleted in the sales table. how to write for a particular item update
Posted

1 solution

SQL
create trigger cascade_utrig
on titles
for update as
if update(title_id)
begin
     update titleauthor
           set title_id = inserted.title_id
           from titleauthor, deleted, inserted
           where deleted.title_id = titleauthor.title_id
     update roysched
           set title_id = inserted.title_id
           from roysched, deleted, inserted
           where deleted.title_id = roysched.title_id
     update salesdetail
           set title_id = inserted.title_id
           from salesdetail, deleted, inserted
           where deleted.title_id = salesdetail.title_id
end

Please read more about Triggers here:
CREATE TRIGGER (Transact-SQL)[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900