Hi all, I didn't write any trigger for my works. Now i want to know how to write trigger . And where it write . Is it possible to write trigger as sql query in phpmyadmin ..
Please help me to write a simple trigger...
I tried like below
Create Trigger sales_bi_trg
BEFORE INSERT ON sales
FOR EACH ROW
BEGIN
DECLARE num_row INTEGER ;
DECLARE tot_rows INTEGER ;
SELECT COUNT(*)
INTO tot_rows
FROM sales
WHERE employee_id = NEW.employee_id ;
IF num_row > 0 THEN
UPDATE perfomance
SET total_sales = NEW.sale_amt + total_sales,
ave_sale = total_sales/(tot_rows + 1)
WHERE employee_id = NEW.employee_id ;
ELSE
INSERT INTO perfomance
(employee_id, name, total_sales,ave_sale)
VALUES (NEW.employee_id, NEW.name, NEW.sale_amt, NEW.sale_amt) ;
END IF ;
Thanks in advance Nisanth