title: Where do I write MySQL trigger
body: <p>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.</p>
  
  <p>Please help me to write a simple trigger...</p>
  
  <p>I tried like below</p>
  
  <pre><code>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 &gt; 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 ;
  </code></pre>
  
  <p>Thanks in advance
  Nisanth </p>