MySql创建触发器

时间:2021-03-25 11:00:02

针对某个大表查询比较慢,

加一个表,存放最新的记录,查询时 查询该表 提高查询性能


DROP TRIGGER trigger_tableBigDataLastest

CREATE TABLE tableBigDataLatest LIKE runningrecord

CREATE TRIGGER trigger_tableBigDataLatest
AFTER INSERT
ON tableBigData
FOR EACH ROW
BEGIN
DELETE FROM tableBigData WHERE SystemNo=new.SystemNo ;

    INSERT INTO tableBigData( SystemNo, Longitude, Latitude, CurrentValue, `MaxValue`, MinValue)
    VALUES(new.SystemNo, new.Longitude, new.Latitude,new.CurrentValue, new.`MaxValue`, new.MinValue );

END;