I am currently new in Firebird, especially in triggers. Usually, I do this in script manually, but I am really fascinated to create it with trigger.
Please let me explain my tables first.
***STOCK***
CODE
NAME
TOTAL
GOOD
BROKEN
SERVICE
***DETAIL***
ID
STOCK_CODE
SERIAL
***BROKEN***
DETAIL_ID
MARK
***SERVICE***
DETAIL_ID
START_DATE
END_DATE
COST
***LOGS***
DETAIL_ID
MARK
START_DATE
END_DATE
COST
And now my problems:
-
How to modify STOCK.GOOD and STOCK.BROKEN value after insert a new record into BROKEN? That will be: STOCK.GOOD-1, STOCK.BROKEN+1.
-
How to insert all record from BROKEN and SERVICE into LOGS before current record in SERVICE is deleted?
I hope my questions could be accepted.
Below are two triggers:
By the way, what is a reason to put mark into a separate table? It belongs to STOCK, doesn’t it?