DELIMITER $$
CREATE TRIGGER `update_data` AFTER UPDATE on `tb_partctrl`
FOR EACH ROW
BEGIN
DECLARE col_name CHAR(10);
DECLARE num_rows int(4);
DECLARE i int(4);
DECLARE col_names CURSOR FOR SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = 'tb_partctrl';
SELECT FOUND_ROWS() into num_rows;
SET i = 1;
the_loop: LOOP
IF i > num_rows THEN
CLOSE col_names;
LEAVE the_loop;
END IF;
FETCH col_names INTO col_name;
IF NEW.col_name <> OLD.col_name THEN //มันบอกว่าไม่รู้จัก col_name ค่ะ
INSERT INTO tb_hispartctrl (modifydate, Fieldchange, Oldvalue, Newvalue) VALUES (NOW(),col_name,NEW.col_name,OLD.col_name);
END IF;
SET i = i + 1;
END LOOP the_loop;
END$$
DELIMITER ;