Code:
CREATE TRIGGER trig_Insert_tbl2
ON tbl2
FOR INSERT
AS
UPDATE tbl1 SET tbl1.Quantity = tbl1.Quantity - Inserted.rused
FROM tbl1, Inserted
WHERE tabl1.material = Inserted.rpaper
This should be what you are looking for, on the insert operation stuff.
then original value of tbl2.rused should be got and added with tbl1.material and then
the updated value of tbl2.rpaper should be got and subracted with
the tbl1.material and updated back to tbl1.material
On the above statement, I am confused a bit. When you say tabl1.material = tbl2.rpaper I hope tabl1.material has reference to tbl2.rpaper or the other way round. But if the tbl1.material is updated, does it not break the reference? How do you maintain data integrity in doing so? What datatypes are tbl1.material, tbl2.rused and tbl2.rpaper as you do add/subtract involving these three columns?
Can you explain us on that?
_________________________
- Vijay G
Strive for Perfection