Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <ol> <li><code>t1</code> will be not be <a href="http://dev.mysql.com/doc/refman/5.0/en/lock-tables-and-triggers.html" rel="nofollow">locked implicitly</a>, as the docs for implicit locking explain would be the case if you were doing the reverse (locking <code>t1</code> will lock <code>t2</code></li> <li>A MySQL Error (ERROR 1100 (HY000): Table <code>t1</code> was not locked with LOCK TABLES) will be generated on attempting to insert into <code>t1</code> because it has not been locked, but the destination of its trigger has.</li> <li>N/A, the query to write to <code>t1</code> is not permitted by the MySQL engine.</li> </ol> <p>Please consider your use case here however. If you are simply copying INSERTS into another table, and not calculating something, you might want to give a thought to using replication instead.</p> <p>Verified on MySQL 5.1 with the following SQL of a toy action log:</p> <pre><code>DROP TABLE IF EXISTS acts, actions; CREATE TABLE acts ( act_id int unsigned not null auto_increment primary key, user_id int unsigned not null ) ENGINE=innodb; CREATE TABLE actions ( action_id int unsigned not null auto_increment primary key, act_id int unsigned not null, user_id int unsigned not null ) ENGINE=innodb; DELIMITER # CREATE TRIGGER acts_post_ins_trigger AFTER INSERT ON acts FOR EACH ROW BEGIN INSERT INTO actions(act_id, user_id) VALUES (new.act_id, new.user_id); END# DELIMITER ; INSERT INTO acts VALUES(1,2); SELECT * FROM acts; SELECT * FROM actions; LOCK TABLE actions WRITE; SELECT('trying to SELECT acts w/ actions locked...') AS 'SELECT TEST'; SELECT * FROM acts; SELECT('trying to INSERT into acts w/ actions locked...') AS 'INSERT TEST'; INSERT INTO acts VALUES(3,4); UNLOCK TABLES; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload