0% found this document useful (0 votes)
6 views1 page

TRG Update

The document describes a trigger that is created on the orders table. The trigger runs for insert operations and checks that the quantity being inserted does not exceed the stock quantity for that item. It prints an error message and rolls back the transaction if the quantity exceeds stock. Otherwise it updates the stock quantity by deducting the ordered quantity.

Uploaded by

venkatbj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

TRG Update

The document describes a trigger that is created on the orders table. The trigger runs for insert operations and checks that the quantity being inserted does not exceed the stock quantity for that item. It prints an error message and rolls back the transaction if the quantity exceeds stock. Otherwise it updates the stock quantity by deducting the ordered quantity.

Uploaded by

venkatbj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

create trigger trgUpdate

on orders
for insert
as
begin
declare @in char(3),
@qtyItems int,
@qtyOrders int
begin tran
select @in=ino from inserted
select @qtyitems=qty from stock where ino=@in
select @qtyorders=qty from inserted

if @qtyorders>@qtyitems
begin
print 'Quantity should not exceed stock limit'
rollback tran
end
else
update stock set qty=qty-@qtyorders
where ino=@in
end

Using trigger:-
----------------
1.
insert into orders values(100,getdate(),'I1',50)
--enters the record into orders table and deducts 50 from qty field of stock
table

2.
insert into orders values(101,getdate(),'I2',250)
--prints the message.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy