Question
Please help and answer both parts

ASSIGNMENT 5: CREATE & EXECUTE Database Trigger titled stock update that automatically inserts a row in stock log table, wh
0 0
Add a comment Improve this question Transcribed image text
Answer #1

CREATE OR REPLACE TRIGGER stock_update

ON Stock

FOR UPDATE

AS

BEGIN

         INSERT INTO stock_log

         (stkcode, old_stkprice, new_stkprice, old_stkqty, new_stkqty, update_stktime)

         SELECT d.stkcode, d.stkprice, i.stkprice, d.stkqty, i.stkqty, CURRENT_TIMESTAMP

          FROM deleted d, inserted i

          where d.stkcode = i.stkcode

END

GO

In this trigger we are inserting values to stock_log table by fetching values from deleted and inserted stock table using

         SELECT d.stkcode, d.stkprice, i.stkprice, d.stkqty, i.stkqty, CURRENT_TIMESTAMP

          FROM deleted d, inserted i

          where d.stkcode = i.stkcode

(during update there will be two table maintained by the DMBS

1. is old or deleted

2. is new or updated or inserted )

Add a comment
Know the answer?
Add Answer to:
Please help and answer both parts ASSIGNMENT 5: CREATE & EXECUTE Database Trigger titled 'stock update'...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT