-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhistory_trigger.sql
48 lines (47 loc) · 1012 Bytes
/
history_trigger.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
DELIMITER //
DROP TRIGGER IF EXISTS after_stock_mng_stock_update//
CREATE TRIGGER after_stock_mng_stock_update AFTER UPDATE ON stock_mng_stock FOR EACH ROW
BEGIN
IF new.issued_quantity = 0
THEN INSERT INTO stock_mng_stockhistory(
id,
last_updated,
category_id,
item_name,
issued_quantity,
quantity,
received_quantity,
received_by)
VALUES(
new.id,
new.last_updated,
new.category_id,
new.item_name,
new.issued_quantity,
new.quantity,
new.received_quantity,
new.received_by);
ELSEIF new.received_quantity = 0
THEN INSERT INTO stock_mng_stockhistory(
id,
last_updated,
category_id,
item_name,
received_quantity,
quantity,
issued_quantity,
issued_by,
issued_to)
VALUES(
new.id,
new.last_updated,
new.category_id,
new.item_name,
new.received_quantity,
new.quantity,
new.issued_quantity,
new.issued_by,
new.issued_to);
END IF;
END//
DELIMITER ;