I didn’t write any trigger for my works. Now i want to know how to write trigger and where do I write it. 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
In phpMyAdmin you can create the trigger in the SQL window.
You may have to set the delimieter to something like “$$” instead of the default “;”. You can change this easily from the bottom of the SQL window.
Delimiter in phpMyAdmin http://img52.imageshack.us/img52/9144/phpmyadmin.jpg
In addition, make sure you close your trigger block with the
ENDcommand, which is missing from your example.