title: delete a record before inserting a new record into a table using trigger in mysql
body: <p>I have created a table  <code>test1</code> as</p>
  
  <p>CREATE TABLE test1
     (id INT,
     name VARCHAR(20))
     ENGINE=INNODB;</p>
  
  <p>Now I want to <code>delete</code> a record  from this table before <code>inserting</code> a new record having the same id(that is,record already existing with same id,then insert the new record) .I tried the code give below.</p>
  
  <pre><code>create trigger before_insert_test1 before insert
  on test1
  for each row
  begin
  delete from test1 where id=NEW.id;
  end;
  </code></pre>
  
  <p>but it shows error 
   ERROR 1442 (HY000): Can't update table 'test1' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
  Can anyone help.
  thanks in advance</p>