Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8154613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:24:43+00:00 2026-06-06T16:24:43+00:00

I think I read that the delete trigger doesn’t know what data was deleted

  • 0

I think I read that the delete trigger doesn’t know what data was deleted and loops over the whole table applying the trigger. Is that true?

Does that mean that the before delete loops over the whole table before the data is deleted and after delete loops over the whole table after the delete occurs?

Is there no way to loop over just the deleted records? So If 10 records are deleted loop over them?

DELIMITER $$
DROP TRIGGER  `before_delete_jecki_triggername`$$
CREATE TRIGGER before_delete_triggername
BEFORE DELETE ON table
FOR EACH ROW 
BEGIN
    /*do stuff*/
END$$
DELIMITER ;

Thanks,

Mat

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T16:24:44+00:00Added an answer on June 6, 2026 at 4:24 pm

    I think it was due to a confusion with FOR EACH ROW statement.
    It is only for “matched records for the statement issued before trigger is invoked.”

    If there exists N number of records in a table and matches records for where id=x,
    assuming x causes a result of less than N records, say N-5, then
    FOR EACH ROW causes a loop for N-5 times only.

    UPDATE:
    A sample test run on the rows affected due to FOR EACH ROW statement is shown below.

    mysql> -- create a test table
    mysql> drop table if exists tbl; create table tbl ( i int, v varchar(10) );
    Query OK, 0 rows affected (0.01 sec)
    
    Query OK, 0 rows affected (0.06 sec)
    
    mysql> -- set test data
    mysql> insert into tbl values(1,'one'),(2,'two' ),(3,'three'),(10,'ten'),(11,'eleven');
    Query OK, 5 rows affected (0.02 sec)
    Records: 5  Duplicates: 0  Warnings: 0
    
    mysql> select * from tbl;
    +------+--------+
    | i    | v      |
    +------+--------+
    |    1 | one    |
    |    2 | two    |
    |    3 | three  |
    |   10 | ten    |
    |   11 | eleven |
    +------+--------+
    5 rows in set (0.02 sec)
    
    mysql> select count(*) row_count from tbl;
    +-----------+
    | row_count |
    +-----------+
    |         5 |
    +-----------+
    1 row in set (0.00 sec)
    
    mysql>
    mysql> -- record loop count of trigger in a table
    mysql> drop table if exists rows_affected; create table rows_affected( i int );
    Query OK, 0 rows affected (0.02 sec)
    
    Query OK, 0 rows affected (0.05 sec)
    
    mysql> select count(*) 'rows_affected' from rows_affected;
    +---------------+
    | rows_affected |
    +---------------+
    |             0 |
    +---------------+
    1 row in set (0.00 sec)
    
    mysql>
    mysql> set @cnt=0;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql>
    mysql> -- drop trigger if exists trig_bef_del_on_tbl;
    mysql> delimiter //
    mysql> create trigger trig_bef_del_on_tbl before delete on tbl
        ->   for each row begin
        ->     set @cnt = if(@cnt is null, 1, (@cnt+1));
        ->
        ->     /* for cross checking save loop count */
        ->     insert into rows_affected values ( @cnt );
        ->   end;
        -> //
    Query OK, 0 rows affected (0.00 sec)
    
    mysql>
    mysql> delimiter ;
    mysql>
    mysql> -- now let us test the delete operation
    mysql> delete from tbl where i like '%1%';
    Query OK, 3 rows affected (0.02 sec)
    
    mysql>
    mysql> -- now let us see what the loop count was
    mysql> select @cnt as 'cnt';
    +------+
    | cnt  |
    +------+
    | 3    |
    +------+
    1 row in set (0.00 sec)
    
    mysql>
    mysql> -- now let us see the table data
    mysql> select * from tbl;
    +------+-------+
    | i    | v     |
    +------+-------+
    |    2 | two   |
    |    3 | three |
    +------+-------+
    2 rows in set (0.00 sec)
    
    mysql> select count(*) row_count from tbl;
    +-----------+
    | row_count |
    +-----------+
    |         2 |
    +-----------+
    1 row in set (0.00 sec)
    
    mysql> select count(*) 'rows_affected' from rows_affected;
    +---------------+
    | rows_affected |
    +---------------+
    |             3 |
    +---------------+
    1 row in set (0.00 sec)
    
    mysql>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please read the whole question; I personally think that this is programming-related; if you
I know that XHTML doesn't support nested form tags and I have already read
I think I read somewhere that some modules only have object oriented interfaces (
From what I've read from Herb Sutter and others you would think that volatile
I've read Visual VM remotely over ssh but I think I've not fully understood
I stumbled over a curious bug, I think: I tried to read 512 as
I know that new-ing something in one module and delete-ing it in another can
I am using async_read_some to read data from a port that is saved in
I've read this Android save app settings/data in Internal/External Storage but I don't think
I think I read every single web page relating to this problem but I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.