MySql 触发器

DELIMITER $$

DROP TRIGGER /*!50032 IF EXISTS */ `99aw`.`BrowseToIntegral`$$

CREATE
    /*!50017 DEFINER = 'root'@'localhost' */
    TRIGGER `BrowseToIntegral` AFTER INSERT ON `visit_me`
    FOR EACH ROW BEGIN
DECLARE LogNum int DEFAULT 0;
DECLARE MyPoint int DEFAULT 0;
DECLARE BrowsNum int DEFAULT 0;
SELECT  COUNT(*) INTO LogNum FROM visit_me where C_mid = NEW.C_mid and w_mid = NEW.w_mid;

/*防止恶意刷流量*/
IF LogNum <= 1 THEN
SELECT points INTO MyPoint FROM member WHERE mid = NEW.w_mid;
SELECT COUNT(*) INTO BrowsNum FROM (SELECT DISTINCT * FROM visit_me WHERE w_mid = NEW.w_mid GROUP BY C_mid ORDER BY C_mid) AS t;
/*每五百流量加1000积分*/
insert into testt(BrowsNum) values(BrowsNum);
IF BrowsNum > 0 AND BrowsNum % 500 = 0 THEN
SET MyPoint = MyPoint + 1000;
insert into testt(MyPoint) values(MyPoint);
UPDATE member SET points = 0 WHERE points IS NULL;
UPDATE member SET points = MyPoint WHERE mid = NEW.w_mid;
END IF;
END IF;


    END;
$$

DELIMITER ;

你可能感兴趣的:(C++,c,mysql,C#)