I have these back to back triggers that I invoking in a SQLite database. I have a table called weight that I am using to calculate BMI, and NIH Health standards classification for the weight. This is how my code looks like:
CREATE TABLE weight(
id INTEGER PRIMARY KEY,
date_and_time TEXT,
weight_in_lb INTEGER,
height_ft INTEGER,
height_in INTEGER,
BMI FLOAT,
reference TEXT
);
CREATE TRIGGER insert_BMI
AFTER INSERT ON weight
FOR EACH ROW
BEGIN
UPDATE weight
SET BMI = (NEW.weight_in_lb/POWER(NEW.height_ft * 12 + NEW.height_in,2)) * 703
WHERE id = NEW.id;
END;
CREATE TRIGGER insert_reference_overweight
AFTER INSERT ON weight
FOR EACH ROW
WHEN NEW.BMI > 25
BEGIN
UPDATE weight
SET reference = 'OVERWEIGHT'
WHERE id=NEW.id;
END;
INSERT INTO weight(id,date_and_time,weight_in_lb,height_ft,height_in)
VALUES(1,'4/20/2000',272,5,10);
For some reason the second trigger does not create the reference value I desire is it because the structure of the trigger does not detect the same id of 1? Or is there a way to make that trigger run after my first trigger?
I would like the overweight reference to appear in the table.