title: Trigger for count number of deletes
body: <p>I have this table called books</p>
  
  <pre><code>create table books (price INT,title VARCHAR(50),type VARCHAR(5));
  </code></pre>
  
  <p>And I need a trigger that inserts in another table called <code>myregister</code> the current date, and the number of books deleted in that date. So I came up with this:</p>
  
  <pre><code>    CREATE TABLE myregister (dates DATE,number INT);
  
      DELIMITER |
      CREATE TRIGGER deleted AFTER DELETE on books
      FOR EACH ROW BEGIN
      set @cnt = if(@cnt is null, 1, (@cnt+1));
      set @dat = CURDATE();
      INSERT INTO myregister values(CURDATE(),@cnt);
      END;
      |
      DELIMITER ;
  </code></pre>
  
  <p>but there are 2 problems: </p>
  
  <ol>
  <li><p>The variable is global, and it counts for every book deleted, it doesn't matter the date.</p></li>
  <li><p>The trigger counts for every row, so at the end, the table myregister has <code>n</code> rows, each one for every book deleted.</p></li>
  </ol>