<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
    <channel>
        <title>MySQL Forums - Triggers</title>
        <description>Forum for MySQL Triggers</description>
        <link>https://forums.mysql.com/list.php?99</link>
        <lastBuildDate>Wed, 22 Apr 2026 14:16:04 +0000</lastBuildDate>
        <generator>Phorum 5.2.23</generator>
        <item>
            <guid>https://forums.mysql.com/read.php?99,740147,740147#msg-740147</guid>
            <title>Execute external script/program (no replies)</title>
            <link>https://forums.mysql.com/read.php?99,740147,740147#msg-740147</link>
            <description><![CDATA[ OK, I cry UNCLE<br />
<br />
I have a need to execute an bash script or a php program when an insert of update to a table happens.  The web says create a trigger &quot;sys_exec ...&quot;.   The web says no longer supported, else where see github server-11 which I can&#039;t get to compile.  Has the work been embedded in Mariad?  And please - detail. <br />
<br />
thank you]]></description>
            <dc:creator>chuck lidderdale</dc:creator>
            <category>Triggers</category>
            <pubDate>Fri, 24 Jan 2025 15:18:55 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?99,711953,711953#msg-711953</guid>
            <title>deadlock happens (no replies)</title>
            <link>https://forums.mysql.com/read.php?99,711953,711953#msg-711953</link>
            <description><![CDATA[ I execute as the following in my code then deadlock happens. Do you know why deadlock happen and have any solutions to resolve ?<br />
begin transaction;<br />
loop {<br />
 insert data into A table;<br />
 insert data into B table; (get id from a table to insert and some another values)<br />
 update data into A table by id.<br />
}<br />
commit;]]></description>
            <dc:creator>jun jun</dc:creator>
            <category>Triggers</category>
            <pubDate>Tue, 05 Dec 2023 09:16:42 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?99,711952,711952#msg-711952</guid>
            <title>deadlock happens (no replies)</title>
            <link>https://forums.mysql.com/read.php?99,711952,711952#msg-711952</link>
            <description><![CDATA[ I execute as the following in my code then deadlock happens. Do you know why deadlock happen and have any solutions to resolve ?<br />
 <br />
loop {<br />
 insert data into A table;<br />
 insert data into B table; (get id from a table to insert and some another values)<br />
 update data into A table by id.<br />
<br />
}]]></description>
            <dc:creator>jun jun</dc:creator>
            <category>Triggers</category>
            <pubDate>Tue, 05 Dec 2023 09:09:21 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?99,709919,709919#msg-709919</guid>
            <title>Trigger with case possible? (no replies)</title>
            <link>https://forums.mysql.com/read.php?99,709919,709919#msg-709919</link>
            <description><![CDATA[ Hello,<br />
<br />
I&#039;m rather new to triggers, here is what I want to do &#039;after update&#039; on a certain table.<br />
<br />
I want to check the value of a field like :<br />
<br />
progress bigger the 0 but less then 100 -&gt; insert a log into a second table<br />
progress equals 100 -&gt; insert another record into the second table<br />
<br />
Can this be done by triggers?<br />
<br />
Regards<br />
Erwin]]></description>
            <dc:creator>erwin traas</dc:creator>
            <category>Triggers</category>
            <pubDate>Sat, 09 Sep 2023 14:23:43 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?99,707125,707125#msg-707125</guid>
            <title>Insufficient checks for trigger (no replies)</title>
            <link>https://forums.mysql.com/read.php?99,707125,707125#msg-707125</link>
            <description><![CDATA[ Sometimes the trigger can be confusing. For example:<br />
<br />
1. Trigger can be created successfully to handle an non-existing tables(t2), and it&#039;s definer can be an no-existing user(user_1), just like:<br />
<br />
DELIMITER ;;<br />
/*!50003 CREATE*/ /*!50017 DEFINER=`user_1`@`%`*/ /*!50003 TRIGGER `trigger_1` AFTER UPDATE ON `t1` FOR EACH ROW BEGIN<br />
            INSERT INTO t2 VALUES(new.id);<br />
END */;;<br />
<br />
As a result, when update on t1, errors will happen. In my opinion, this trigger should not be successfully created in this case. Errors should be found in the create phase instead of the use phase.<br />
<br />
2. Trigger can be created successfully to handle an non-existing column(col_1), just like:<br />
<br />
DELIMITER ;;<br />
/*!50003 CREATE*/ /*!50017 DEFINER=`user`@`%`*/ /*!50003 TRIGGER `trigger_2` AFTER UPDATE ON `t1` FOR EACH ROW BEGIN<br />
            select col_1 from t3;<br />
END */;;<br />
<br />
If t1 has the field col_1, but t3 does not, and user don&#039;t know or forget trigger2, then the error report will be quite confusing. The error message is &quot;Unknown column &#039;col_1&#039; in &#039;field list&#039;&quot;, but it is insuffient, because we don&#039;t know &quot;col_1&quot; is in which table. As a user, I will first check table &quot;t1&quot; instead of trigger &quot;trigger_2&quot;(table &quot;t3&quot;).<br />
<br />
This might be by design, but in some cases, it can be really confusing.]]></description>
            <dc:creator>Huaxiong Song</dc:creator>
            <category>Triggers</category>
            <pubDate>Tue, 03 Jan 2023 04:57:37 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?99,705241,705241#msg-705241</guid>
            <title>Mysql How to Sync two Database Tables which are on Different Machines Every Few Minutes (1 reply)</title>
            <link>https://forums.mysql.com/read.php?99,705241,705241#msg-705241</link>
            <description><![CDATA[ In MySQL how can I sync two Database Tables which are on Different Machines Every Few Minutes?<br />
Please give me any examples and steps]]></description>
            <dc:creator>Frank Moori</dc:creator>
            <category>Triggers</category>
            <pubDate>Wed, 13 Jul 2022 19:03:50 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?99,705239,705239#msg-705239</guid>
            <title>How to check if database is up before my Trigger fires? (2 replies)</title>
            <link>https://forums.mysql.com/read.php?99,705239,705239#msg-705239</link>
            <description><![CDATA[ Hello every one,<br />
I&#039;m wondering if there is a way to check if database is up before my Trigger fires?<br />
and how my trigger can resume from where it left after the DB server is back on and running?<br />
Thanks]]></description>
            <dc:creator>Frank Moori</dc:creator>
            <category>Triggers</category>
            <pubDate>Wed, 24 May 2023 07:21:40 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?99,705080,705080#msg-705080</guid>
            <title>I need help with if statement in my trigger statement (1 reply)</title>
            <link>https://forums.mysql.com/read.php?99,705080,705080#msg-705080</link>
            <description><![CDATA[ create trigger idcheck after insert on customers<br />
for each row<br />
if (select exists(select * from customers where `Last Name`=&quot;Ma&quot;))<br />
then<br />
rollback;<br />
end if;<br />
<br />
this is my query. can you tell me what I&#039;m doing wrong with my if statement?]]></description>
            <dc:creator>Eric Ma</dc:creator>
            <category>Triggers</category>
            <pubDate>Tue, 28 Jun 2022 13:15:01 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?99,704164,704164#msg-704164</guid>
            <title>Error 1442 / trigger failing / due to select in insert statement (1 reply)</title>
            <link>https://forums.mysql.com/read.php?99,704164,704164#msg-704164</link>
            <description><![CDATA[ First, apologies for cross-posting - Posted to the wrong forum initially:<br />
<br />
Good evening.<br />
<br />
I am aware of the cause of error 1442 in relation to not being able to update a row in a table being called from the trigger in general, but I cannot understand why a trigger fails if the insert statement contains only a select from the table in question<br />
<br />
Create trigger t1 in rating<br />
for each row<br />
begin<br />
  update title set f1 = new.vote where title.id = new.title_id<br />
end<br />
<br />
My insert is:<br />
<br />
insert into rating (title_id, vote) values (select id from title where title_name = &#039;FRED1&#039;,25);<br />
<br />
The issue is because I am selecting a value from the title table, I cannot update it in the body of the trigger.  Surely if it is only selecting then it does not have the potential to cause an infinite-loop, which is what I understand to be the reason why this is not allowed?<br />
<br />
Having searched around, I cannot find how to get around this?  Are there any &#039;standard&#039; techniques that people are aware of? <br />
<br />
Thank you<br />
<br />
Stewart Bourke]]></description>
            <dc:creator>Stewart Bourke</dc:creator>
            <category>Triggers</category>
            <pubDate>Thu, 28 Apr 2022 15:34:22 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?99,704082,704082#msg-704082</guid>
            <title>After Update Trigger if field = 1 (1 reply)</title>
            <link>https://forums.mysql.com/read.php?99,704082,704082#msg-704082</link>
            <description><![CDATA[ Needs Answer MySQL<br />
1<br />
Hi<br />
<br />
I am hoping someone can help me out with a project I need to hand up. I need to design a basic DB with tables, data, queries, views, triggers etc. I am trying to create a trigger but it isn&#039;t working.<br />
<br />
I have a transaction table called tblLoan and wanted an after update trigger on this table only if the late column = 1. The idea is the trigger would write the LoanID and MemebrID from tblLoan table into the tblLate table. My code is below, and I have tried different permutations of this.<br />
<br />
SQL<br />
delimiter //<br />
CREATE TRIGGER Update_tblLoan_new<br />
AFTER UPDATE<br />
ON tblLoan FOR EACH ROW<br />
BEGIN<br />
IF (late = 1)<br />
THEN<br />
INSERT INTO tblLate (LoanID, MemberID ) VALUES (LoanID,MemberID);<br />
END IF;<br />
END; //<br />
<br />
Error I get is below. Not 100% but it looke like my code it trying toSET the late value into my tblLoan table.<br />
<br />
ERROR 1054: 1054: Unknown column &#039;late&#039; in &#039;field list&#039;<br />
SQL Statement:<br />
<br />
<br />
UPDATE `library`.`tblloan` SET `Late` = &#039;1&#039; WHERE (`LoanID` = &#039;1&#039;)<br />
<br />
Thanks in advance <br />
<br />
Poco]]></description>
            <dc:creator>Poco Poco</dc:creator>
            <category>Triggers</category>
            <pubDate>Fri, 22 Apr 2022 22:29:27 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?99,703745,703745#msg-703745</guid>
            <title>Trigger on date correction (1 reply)</title>
            <link>https://forums.mysql.com/read.php?99,703745,703745#msg-703745</link>
            <description><![CDATA[ I need to make a trigger on inserting,updating and deleting a row in a table and it must check the correction of the date in a row. the question is: what can i do to make a check on writing date correctly?]]></description>
            <dc:creator>Святослав Тарадай</dc:creator>
            <category>Triggers</category>
            <pubDate>Fri, 01 Apr 2022 16:19:34 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?99,700462,700462#msg-700462</guid>
            <title>ERROR: Unknown column in WHERE clause (7 replies)</title>
            <link>https://forums.mysql.com/read.php?99,700462,700462#msg-700462</link>
            <description><![CDATA[ Here is the trigger for the Song_Entry table after insert:<br />
<br />
UPDATE Contest<br />
SET Songs_Entered =<br />
(Songs_Entered + 1)<br />
WHERE Contest.Contest_id =<br />
Song_Entry.Contest_id;<br />
<br />
I keep getting the above error message that says Song_Entry.Contest_id is unknown.]]></description>
            <dc:creator>Lester Cutchall</dc:creator>
            <category>Triggers</category>
            <pubDate>Wed, 05 Jan 2022 18:00:56 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?99,700412,700412#msg-700412</guid>
            <title>Using tablename in trigger from system (1 reply)</title>
            <link>https://forums.mysql.com/read.php?99,700412,700412#msg-700412</link>
            <description><![CDATA[ Hi<br />
<br />
I am using a trigger to audit the transaction on my tables.<br />
<br />
e.g. on my user table after an update i want to have following information, as my example shows.<br />
<br />
CREATE DEFINER = CURRENT_USER TRIGGER `test`.`dbuser_AFTER_UPDATE`<br />
AFTER UPDATE ON `dbuser` <br />
FOR EACH ROW<br />
<br />
BEGIN<br />
	<br />
    INSERT INTO test_audit<br />
    SET type_of_action = &#039;u&#039;,<br />
    tablename = &#039;test.dbuser&#039;,<br />
    userid = new.userid,<br />
    ip4 = null,<br />
    ip6 = null,<br />
    longitude = null,<br />
    latitude = null,<br />
    time_stamp = NOW();<br />
    <br />
END<br />
<br />
I want to use this trigger on all my tables and i would prefer to use system variable for the table name. Until now, i didn&#039;t found the name of the variable to replace my &#039;test.dbuser&#039; with some kind of a system variable.<br />
<br />
The only information i need is the name of the table, where my trigger is connected.<br />
<br />
Does someone know the name or where i will find it.<br />
<br />
Thanks<br />
Wolfgang]]></description>
            <dc:creator>Wolfgang Ritter</dc:creator>
            <category>Triggers</category>
            <pubDate>Thu, 30 Dec 2021 15:18:47 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?99,697717,697717#msg-697717</guid>
            <title>MySQL to trigger update statement on a specific day &amp; time (3 replies)</title>
            <link>https://forums.mysql.com/read.php?99,697717,697717#msg-697717</link>
            <description><![CDATA[ Hi team,<br />
<br />
I have a requirement in MySQL to trigger an update statement on a calendar table on a specific day &amp; time.<br />
<br />
I understand triggers can only work on the basis of a BEFORE or AFTER state during an update of a field in a table.<br />
<br />
I can not find anywhere for a method to cause a table update, unless I use a cron job.<br />
<br />
Are there any MySQL tools that can run a sql statement on the specific day of the week and time?<br />
<br />
Or is there a work around which will achieve the same result?<br />
<br />
All assistance is appreciated.<br />
<br />
Cheers<br />
Bernard Bailey]]></description>
            <dc:creator>Bernard Bailey</dc:creator>
            <category>Triggers</category>
            <pubDate>Tue, 20 Jul 2021 13:56:42 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?99,697465,697465#msg-697465</guid>
            <title>How to create a before update trigger for 2 fields &quot;expected_hash&quot; and &quot;identify_hash&quot; (both allow null) (5 replies)</title>
            <link>https://forums.mysql.com/read.php?99,697465,697465#msg-697465</link>
            <description><![CDATA[ Hi there<br />
<br />
If identify_hash != expected_hash, the trigger should deny the update.<br />
<br />
I tried EVERYTHING, but there is not solution so it seems...<br />
<br />
Major question: Is that possible with MySQL?<br />
<br />
I get A LOT of strange error messages like &quot;table does not exist in field list&quot;<br />
<br />
Current code is that:<br />
<br />
<br />
SET SQL_NOTES = 0;<br />
<br />
USE pf_server;<br />
<br />
DROP TRIGGER IF EXISTS expected_hash_trigger;<br />
<br />
DELIMITER $$ <br />
CREATE TRIGGER expected_hash_trigger<br />
  BEFORE UPDATE ON clientdb_mapping<br />
FOR EACH ROW<br />
<br />
BEGIN<br />
<br />
 IF (new.identify_hash = clientdb_mapping.expected_hash) THEN<br />
    -- UPDATE clientdb_mapping  SET  identify_hash = clientdb_mapping.expected_hash;<br />
    DELETE FROM pi_hash_migration_mapping;<br />
 END IF;<br />
<br />
END $$ <br />
<br />
DELIMITER ;<br />
<br />
<br />
SET SQL_NOTES = 1;]]></description>
            <dc:creator>Jan Marti</dc:creator>
            <category>Triggers</category>
            <pubDate>Fri, 02 Jul 2021 13:51:36 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?99,696454,696454#msg-696454</guid>
            <title>Help with a trigger to change field to a negative value (2 replies)</title>
            <link>https://forums.mysql.com/read.php?99,696454,696454#msg-696454</link>
            <description><![CDATA[ I have a database called check_register that has one table called transactions. The transactions table has the following columns:<br />
<br />
transID  int     (auto increment) primary key<br />
amount   int  <br />
withdraw varchar  [values are either yes or no]<br />
<br />
<br />
is there a way to write a trigger that will look to see if the withdraw field = yes then change the amount value to a negative value? <br />
<br />
<br />
<br />
for example, a record entered with the following values:<br />
<br />
transID: 1<br />
amount: 20.00<br />
withdraw: yes<br />
<br />
the trigger would replace 20.00 with -20.00<br />
<br />
<br />
<br />
Thank you in advance. I&#039;m trying to teach myself ways to have the database help with data manipulation,]]></description>
            <dc:creator>mark paterson</dc:creator>
            <category>Triggers</category>
            <pubDate>Tue, 11 May 2021 21:46:28 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?99,695870,695870#msg-695870</guid>
            <title>Why isn&#039;t this working? (6 replies)</title>
            <link>https://forums.mysql.com/read.php?99,695870,695870#msg-695870</link>
            <description><![CDATA[ Hey Everyone,<br />
I am working on a database, and I want to set up a trigger. Here is the last outline of the two tables<br />
<br />
<pre class="bbcode">
Lighting:
|Index | col1 | col2 | Last Updated|
------------------------------------
|1     |info  |info. | 1618335050  |


Lighting Schedule:
|Index | time  | strength |
---------------------------
|1     |12:00  |0         |
---------------------------
|2     |13:00. |20        |
---------------------------
|3     |13:15. |25        |
---------------------------
|2     |13:40. |50        |</pre>
<br />
I have a python program that will delete all the rows in `Lighting Schedule` and replace insert new information. What I am looking for is a trigger that put a timestamp into row one column &quot;Last Updated&quot; in the `Lighting` table when that happens<br />
<br />
The code below keeps shooting back a generic error.<br />
<br />
Any ideas?<br />
<br />
<br />
<pre class="bbcode">
DELIMITER $$
CREATE TRIGGER &#039;LightingLastUpdated&#039;
AFTER INSERT
ON `Lighting Schedule`
BEGIN
	UPDATE `Lighting` SET `Last Updated` = TIMESTAMP WHERE &#039;Index&#039; = 1;
END$$

DELIMITER ;
</pre>]]></description>
            <dc:creator>John Frank</dc:creator>
            <category>Triggers</category>
            <pubDate>Wed, 14 Apr 2021 22:06:52 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?99,694333,694333#msg-694333</guid>
            <title>Trigger :Add an old value with the new value (1 reply)</title>
            <link>https://forums.mysql.com/read.php?99,694333,694333#msg-694333</link>
            <description><![CDATA[ I&#039;m trying to create an trigger on phpmyadmin. My objective is to create a trigger that add the old value of a row with the new value (inserted with a form).<br />
<br />
It&#039;s for managing the student dues, so if a student already paid $100, and pay $150 more the other time, the trigger have to add the old value ($100) with the new received value ($150), and the field &#039;already_paid&#039; in the db is now $250.<br />
<br />
I&#039;ve tried something simple like this, but it didn&#039;t worked.<br />
<br />
(TRIED WITH BEFORE UPDATE )<br />
<br />
SET @resultat = already_paid + new.already_paid<br />
UPDATE student_dues<br />
SET already_paid = @resultat<br />
WHERE student_due_id = new.student_due_id<br />
<br />
&amp;<br />
<br />
UPDATE student_dues<br />
SET versement = versement + new.versement<br />
WHERE student_due_id = new.student_due_id]]></description>
            <dc:creator>theo robert</dc:creator>
            <category>Triggers</category>
            <pubDate>Thu, 21 Jan 2021 17:05:24 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?99,694062,694062#msg-694062</guid>
            <title>Debug audit trigger design (3 replies)</title>
            <link>https://forums.mysql.com/read.php?99,694062,694062#msg-694062</link>
            <description><![CDATA[ Hello<br />
<br />
I am an experienced pl/sql developer, now attempting to write a trigger in MySql 5.6 (on AWS) to debug a nasty problem.<br />
In our system there is a table in which a couple of fields are updated to a non-legal value, but we do not understand which process is doing it (we have quite a few of them). <br />
Putting a constraint on the field is not an option (it is a legacy system).<br />
We would like to find out _which_ process is doing this faulty update.<br />
In Oracle I would have written a before update trigger which would <br />
1) collect information on the calling session (program_name, client etc) from the v$session table, <br />
2) insert a record in a audit table, and finally <br />
3) raise an exception to block the undesired update.<br />
<br />
The only thing I was able to achieve was the 3) (raise an exception with signal state &#039;45000&#039;), but inserting into the audit table at the same time is not possible since MySql lacks the concept of autonomous transaction right?<br />
I am looking for an advice, hoping the use case is clear.<br />
What a experienced MySql admin/dev would do in this case?<br />
Thanks a lot<br />
Bye<br />
Nicola]]></description>
            <dc:creator>Nicola Farina</dc:creator>
            <category>Triggers</category>
            <pubDate>Fri, 08 Jan 2021 15:04:51 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?99,694001,694001#msg-694001</guid>
            <title>Would a function or procedure work in my case? Executed by a trigger? (3 replies)</title>
            <link>https://forums.mysql.com/read.php?99,694001,694001#msg-694001</link>
            <description><![CDATA[ I have six tables:<br />
<br />
SALES<br />
S000<br />
S001<br />
S002<br />
S003<br />
S004<br />
<br />
I want to create a trigger so that, when a new record is inserted to any of the tables S000...S004, the field SALES.LAST_DATE in a specific record is updated with the value of the field &quot;SALE_DATE&quot; that was just inserted (in S000...s004).<br />
<br />
Here is pseudo-code:<br />
<br />
---------------------<br />
if table(S000...S004) has a new record inserted then<br />
   x = tablename that was just updated<br />
   y = SALE_DATE from record that was just inserted<br />
   update SALES set LAST_DATE = y where TNAME = x<br />
end if<br />
---------------------<br />
<br />
&quot;TNAME&quot; is a field in SALES that holds the tablename (S000...S004)<br />
<br />
I&#039;ve been working with MySQL for a while, but only simple tables and queries. I&#039;ve never used triggers, functions or procedures.<br />
<br />
Is this workable with a trigger, function or procedure? <br />
<br />
BTW, I cannot change the design of the tables, because some old programs rely on the table structure just the way it is.<br />
<br />
Any advice, suggestions or insights is appreciated in advance! Or even just pointing me in the right direction.<br />
<br />
Thanks!]]></description>
            <dc:creator>Jim Schwartz</dc:creator>
            <category>Triggers</category>
            <pubDate>Mon, 04 Jan 2021 16:30:52 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?99,691074,691074#msg-691074</guid>
            <title>Trigger : AFTER INSERT UPDATE on other table (2 replies)</title>
            <link>https://forums.mysql.com/read.php?99,691074,691074#msg-691074</link>
            <description><![CDATA[ Hi,<br />
<br />
I have 2 tables :<br />
<br />
<br />
1) e_ with :<br />
<br />
id_e (INT AI PRIMARY KEY)<br />
c1   (VARCHAR)<br />
c2   (INT)    <br />
<br />
<br />
2) e_h with :<br />
<br />
id_e_h (INT AI PRIMARY KEY)<br />
d1   (VARCHAR)<br />
d2   (INT) <br />
<br />
------------------------------------------------------------------------------------------<br />
<br />
Using a trigger on e_h AFTER INSERT I&#039;d like to UPDATE c2 WHERE c1 = d1<br />
<br />
But I get the ERROR subquery returns more than 1 row<br />
<br />
------------------------------------------------------------------------------------------<br />
<br />
This is the trigger :<br />
<br />
UPDATE e_ SET c2 =<br />
(SELECT d2 FROM e_h WHERE c1 = d1)<br />
<br />
------------------------------------------------------------------------------------------<br />
<br />
May someone help me on how to fix that issue ?]]></description>
            <dc:creator>MICHAEL FAURE</dc:creator>
            <category>Triggers</category>
            <pubDate>Thu, 12 Nov 2020 17:23:06 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?99,690872,690872#msg-690872</guid>
            <title>trigger with dynamic column name (1 reply)</title>
            <link>https://forums.mysql.com/read.php?99,690872,690872#msg-690872</link>
            <description><![CDATA[ Good morning to all<br />
<br />
At this moment I have the need to create a trigger, but according to the value returned by the month (coldate) function, it updates a specific column in another table.<br />
<br />
I explain:<br />
<br />
Table orders<br />
order_id INT auto_increment<br />
client_id INT<br />
order_date DATE<br />
city_id INT<br />
<br />
Table summary_month_orders<br />
consecutive INT auto_increment<br />
client_id INT<br />
month1 INT<br />
month2 INT<br />
month3 INT<br />
month4 INT<br />
.....<br />
month12 INT<br />
<br />
I need to create a TRIGGER that when inserting a record in the orders summary table adds 1 to the corresponding month field of the month_summary_orders table.<br />
Which means that if I add an order that has the date &#039;2020-10-01&#039;, +1 must be added to the month October from the summary_orders_month table.<br />
<br />
I try in the following way but so far without success<br />
<br />
delimiter //<br />
CREATE TRIGGER add_order AFTER INSERT ON orders<br />
    FOR EACH ROW<br />
    BEGIN<br />
      DECLARE mthdb CHAR(5);<br />
      SELECT CONCAT(&quot;month&quot;,month(NEW.order_date)) INTO mthdb;<br />
 <br />
      UPDATE summary_month_ordersSET mthdb=mthdb +1 WHERE client_id =NEW.client_id <br />
 <br />
      END IF;<br />
    END;//<br />
delimiter;<br />
<br />
It returns syntax error]]></description>
            <dc:creator>LEANDRO AREVALO</dc:creator>
            <category>Triggers</category>
            <pubDate>Mon, 02 Nov 2020 16:29:26 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?99,690696,690696#msg-690696</guid>
            <title>Server crashes after trigger execution (4 replies)</title>
            <link>https://forums.mysql.com/read.php?99,690696,690696#msg-690696</link>
            <description><![CDATA[ Hi guys,<br />
<br />
<br />
I have a trigger in MySQL that is causing the MySQL server to restart each time its triggered. This started happening after the version 8.0.22 update a day ago. My trigger is as follows:<br />
<br />
CREATE TRIGGER max_client_invoice_before_insert<br />
                        BEFORE INSERT<br />
                           ON client_invoices FOR EACH ROW<br />
<br />
                        BEGIN<br />
<br />
                           DECLARE vMax int(11);<br />
<br />
                           SELECT IFNULL(max(client_invoice_id),0) from client_invoices where client_operating_unit_id = NEW.client_operating_unit_id INTO vMax;<br />
<br />
                           SET NEW.client_invoice_id = vMax+1;<br />
<br />
                        END<br />
<br />
Is there anything i am missing due to the recent update or any better and efficient ways of achieving the same goal if i can&#039;t seem to find the cause of the server crashes?<br />
<br />
I have also checked the logs and this is what i find:<br />
<br />
06:03:02 UTC - mysqld got signal 11 ;<br />
Most likely, you have hit a bug, but this error can also be caused by malfunctioning hardware.<br />
Thread pointer: 0x7f08e4921bd0<br />
Attempting backtrace. You can use the following information to find out<br />
where mysqld died. If you see no messages after this, something went<br />
terribly wrong...<br />
stack_bottom = 7f09c8254c70 thread_stack 0x46000<br />
/usr/sbin/mysqld(my_print_stacktrace(unsigned char const*, unsigned long)+0x3d) [0x2194f3d]<br />
/usr/sbin/mysqld(handle_fatal_signal+0x313) [0xff55f3]<br />
/lib64/libpthread.so.0(+0xf630) [0x7f09d5633630]<br />
/usr/sbin/mysqld(Item_splocal::this_item()+0x14) [0x111fce4]<br />
/usr/sbin/mysqld(Item_sp_variable::val_int()+0x13) [0x111fb63]<br />
/usr/sbin/mysqld(Item_func_plus::int_op()+0x1d) [0x11aafdd]<br />
/usr/sbin/mysqld(Item_func_numhybrid::val_int()+0x191) [0x11ad541]<br />
/usr/sbin/mysqld(Item::save_in_field_inner(Field*, bool)+0x125) [0x11259c5]<br />
/usr/sbin/mysqld(Item::save_in_field(Field*, bool)+0x53) [0x113ef03]<br />
/usr/sbin/mysqld(Item_trigger_field::set_value(THD*, sp_rcontext*, Item**)+0x76) [0x113f136]<br />
/usr/sbin/mysqld(sp_instr_set_trigger_field::exec_core(THD*, unsigned int*)+0x90) [0xe38a80]<br />
/usr/sbin/mysqld(sp_lex_instr::reset_lex_and_exec_core(THD*, unsigned int*, bool)+0x60c) [0xe39b1c]<br />
/usr/sbin/mysqld(sp_lex_instr::validate_lex_and_execute_core(THD*, unsigned int*, bool)+0x9a) [0xe3a55a]<br />
/usr/sbin/mysqld(sp_head::execute(THD*, bool)+0x5d3) [0xe311c3]<br />
/usr/sbin/mysqld(sp_head::execute_trigger(THD*, MYSQL_LEX_CSTRING const&amp;, MYSQL_LEX_CSTRING const&amp;, GRANT_INFO*)+0x29d) [0xe31acd]<br />
/usr/sbin/mysqld(Trigger::execute(THD*)+0x10c) [0xfc150c]<br />
/usr/sbin/mysqld(Trigger_chain::execute_triggers(THD*)+0x18) [0xfc28b8]<br />
/usr/sbin/mysqld(Table_trigger_dispatcher::process_triggers(THD*, enum_trigger_event_type, enum_trigger_action_time_type, bool)+0x46) [0xfbc4a6]<br />
/usr/sbin/mysqld(fill_record_n_invoke_before_triggers(THD*, COPY_INFO*, mem_root_deque&lt;Item*&gt; const&amp;, mem_root_deque&lt;Item*&gt; const&amp;, TABLE*, enum_trigger_event_type, int, bool, bool*)+0x3f9) [0xe45ac9]<br />
/usr/sbin/mysqld(Sql_cmd_insert_values::execute_inner(THD*)+0x454) [0x1352464]<br />
/usr/sbin/mysqld(Sql_cmd_dml::execute(THD*)+0x525) [0xf15695]<br />
/usr/sbin/mysqld(mysql_execute_command(THD*, bool)+0x9f0) [0xeb98d0]<br />
/usr/sbin/mysqld(Prepared_statement::execute(String*, bool)+0x8f0) [0xee8160]<br />
/usr/sbin/mysqld(Prepared_statement::execute_loop(String*, bool)+0x117) [0xeec5f7]<br />
/usr/sbin/mysqld(mysqld_stmt_execute(THD*, Prepared_statement*, bool, unsigned long, PS_PARAM*)+0x181) [0xeecba1]<br />
/usr/sbin/mysqld(dispatch_command(THD*, COM_DATA const*, enum_server_command)+0x1712) [0xebfbf2]<br />
/usr/sbin/mysqld(do_command(THD*)+0x19c) [0xec101c]<br />
/usr/sbin/mysqld() [0xfe69e0]<br />
/usr/sbin/mysqld() [0x272fc3e]<br />
/lib64/libpthread.so.0(+0x7ea5) [0x7f09d562bea5]<br />
/lib64/libc.so.6(clone+0x6d) [0x7f09d3a0e8dd]<br />
<br />
 <br />
<br />
Trying to get some variables.<br />
Some pointers may be invalid and cause the dump to abort.<br />
Query (7f08e5343368): insert into `client_invoices` (`customer_id`, `invoice_date`, `sub_total`, `vat`, `total`, `client_operating_unit_id`, `client_invoice_id`, `invoiced`, `paid`, `created_by`, `updated_by`, `updated_at`, `created_at`) values (459, &#039;2020-10-18 08:03:01&#039;, &#039;24202.53&#039;, &#039;0&#039;, &#039;24202.53&#039;, 1, 0, 0, 0, 47, 47, &#039;2020-10-20 08:03:02&#039;, &#039;2020-10-20 08:03:02&#039;)<br />
Connection ID (thread ID): 743<br />
Status: NOT_KILLED<br />
<br />
 <br />
<br />
The manual page at <a href="http://dev.mysql.com/doc/mysql/en/crashing.html"  rel="nofollow">http://dev.mysql.com/doc/mysql/en/crashing.html</a> contains<br />
information that should help you find out what is causing the crash.<br />
2020-10-20T06:03:04.667817Z 0 [Warning] [MY-011070] [Server] &#039;Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it&#039; is deprecated and will be removed in a future release.<br />
2020-10-20T06:03:04.668382Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.22) starting as process 59229<br />
2020-10-20T06:03:04.685040Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.<br />
2020-10-20T06:03:07.357601Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.<br />
2020-10-20T06:03:08.537376Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: &#039;::&#039; port: 33060, socket: /var/run/mysqld/mysqlx.sock<br />
2020-10-20T06:03:08.656148Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.<br />
2020-10-20T06:03:08.656724Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.<br />
2020-10-20T06:03:08.733111Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: &#039;8.0.22&#039;  socket: &#039;/var/lib/mysql/mysql.sock&#039;  port: 3306  MySQL Community Server - GPL.]]></description>
            <dc:creator>Leopold Ramsy</dc:creator>
            <category>Triggers</category>
            <pubDate>Fri, 23 Oct 2020 15:50:51 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?99,690407,690407#msg-690407</guid>
            <title>How I can make the trigger calculates the sum of a column for specific condition (1 reply)</title>
            <link>https://forums.mysql.com/read.php?99,690407,690407#msg-690407</link>
            <description><![CDATA[ I have table employees as following<br />
<br />
<pre class="bbcode">CREATE TABLE `employees`
(
  `Employee_Id` Int NOT NULL AUTO_INCREMENT,
  `Employeer_Name` Char(150) NOT NULL,
  `Job` Varchar(100),
  `Salary` Decimal(10,2),
  PRIMARY KEY (`Employee_Id`)
) ENGINE = InnoDB
 AUTO_INCREMENT = 1
 ROW_FORMAT = Compact
;</pre>
<br />
During a month the employee can borrow some money from his salary many times,<br />
it&#039;s required to record that amount of money borrowed , the remaining money from his monthly salary each time.<br />
<br />
So I created table Salary_Transaction to record the transactions of borrowing and receiving money<br />
<br />
<pre class="bbcode">CREATE TABLE `Salary_Transaction`
( `Salary_Transaction_Id` Int NOT NULL AUTO_INCREMENT,
  `money_amount` Decimal(10,2) NOT NULL,
  `Employee_Id` Int,
  PRIMARY KEY (`Salary_Transaction_Id`) );</pre>
<br />
And I created a table called debt_alerts to display the remaining money from the salary <br />
<br />
<pre class="bbcode">
CREATE TABLE `debt_alerts`
(
  `Debt_alert_id` Int NOT NULL AUTO_INCREMENT,
  `Salary_Transaction_Id` Int,
  `Remaining_money` Decimal(10,2),
  `Employee_Id` Int,
  PRIMARY KEY (`Debt_alert_id`)
) ENGINE = InnoDB
 AUTO_INCREMENT = 5
 ROW_FORMAT = Compact
;</pre>
<br />
--These are my indexes relationships<br />
<br />
<pre class="bbcode">
CREATE INDEX `IX_Relationship23` USING BTREE ON `debt_alerts` (`Salary_Transaction_Id`)
;

CREATE INDEX `IX_Relationship33` ON `debt_alerts` (`Employee_Id`)
;

CREATE INDEX `IX_Relationship11` USING BTREE ON `salary_transaction` (`Employee_Id`)
;
ALTER TABLE `salary_transaction` ADD CONSTRAINT `Relationship11` FOREIGN KEY (`Employee_Id`) REFERENCES `employees` (`Employee_Id`) ON DELETE CASCADE ON UPDATE CASCADE
;


ALTER TABLE `debt_alerts` ADD CONSTRAINT `Relationship23` FOREIGN KEY (`Salary_Transaction_Id`) REFERENCES `salary_transaction` (`Salary_Transaction_Id`) ON DELETE CASCADE ON UPDATE CASCADE
;

ALTER TABLE `debt_alerts` ADD CONSTRAINT `Relationship18` FOREIGN KEY (`Employee_Id`) REFERENCES `employees` (`Employee_Id`) ON DELETE CASCADE ON UPDATE CASCADE
;</pre>
<br />
For accomplishment of my task I created this trigger<br />
<pre class="bbcode">
DELIMITER $$
CREATE trigger Remaining_money_calc
AFTER INSERT ON Salary_Transaction 
FOR EACH ROW 
BEGIN
INSERT INTO debt_alerts(Remaining_money,Employee_Id,Salary_Transaction_Id) 
SELECT y.y-x.x,NEW.Employee_Id ,NEW.Salary_Transaction_Id
FROM ( SELECT SUM(money_amount) x
       FROM Salary_Transaction 
       WHERE Salary_Transaction_Id =  Salary_Transaction_Id ) x
JOIN ( SELECT Employees.Salary y 
       FROM Employees
       WHERE NEW.Employee_Id=Employees.Employee_Id 
       LIMIT 1 ) y;
END
$$ DELIMITER ;</pre>
<br />
 The problem this trigger calculate the sum of all remaining_money in the debt_alerts table, I want it to do that for specific employee only.]]></description>
            <dc:creator>Robin vanpersie</dc:creator>
            <category>Triggers</category>
            <pubDate>Sun, 04 Oct 2020 17:19:16 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?99,688631,688631#msg-688631</guid>
            <title>Issues with converting update command to trigger (13 replies)</title>
            <link>https://forums.mysql.com/read.php?99,688631,688631#msg-688631</link>
            <description><![CDATA[ Current command: <br />
[sensor_logs]&gt; UPDATE telemetry_log JOIN id_name_update ON telemetry_log.device_id  = id_name_update.device_id  SET telemetry_log.device_desc = id_name_update.device_desc WHERE telemetry_log.device_desc IS NULL;<br />
(this works)<br />
<br />
I would like to create a trigger to do this automatically.<br />
I have tried 100&#039;s of possible triggers configurations, all of them ending with a error either 1064 sql syntax or 1442 same table. <br />
<br />
table 1 id_name_update<br />
[sensor_logs]&gt; show columns in id_name_update;<br />
<br />
<br />
+-------------+----------+------+-----+---------+-------+<br />
| Field       | Type     | Null | Key | Default | Extra |<br />
+-------------+----------+------+-----+---------+-------+<br />
| device_id   | char(50) | NO   | PRI | NULL    |       |<br />
| device_desc | char(50) | YES  |     | NULL    |       |<br />
| hum_cal     | int(11)  | NO   |     | 0       |       |<br />
| temp_cal    | int(11)  | NO   |     | 0       |       |<br />
+-------------+----------+------+-----+---------+-------+<br />
<br />
<br />
 [sensor_logs]&gt; select * from id_name_update;<br />
<br />
+-----------+------------------+---------+----------+<br />
| device_id | device_desc      | hum_cal | temp_cal |<br />
+-----------+------------------+---------+----------+<br />
| 11        | PaaRoomByFreezer |       0 |        0 |<br />
| 13        | Compressor       |       0 |        0 |<br />
| 15        | PaaLab           |       0 |        0 |<br />
| 16        | PottingArea      |       0 |        0 |<br />
| 30        | BondFront        |       0 |        0 |<br />
| 60        | RightFreezerAir  |       0 |        0 |<br />
| 62        | LeftFreezerAir   |       0 |        0 |<br />
| 71        | PaaNewRoom       |       0 |        0 |<br />
| 72        | BondBack         |       0 |        0 |<br />
| 73        | PrimerBooth      |       0 |        0 |<br />
+-----------+------------------+---------+----------+<br />
<br />
Table 2<br />
[sensor_logs]&gt; show columns in telemetry_log;<br />
+-----------------+----------+------+-----+---------+----------------+<br />
| Field           | Type     | Null | Key | Default | Extra          |<br />
+-----------------+----------+------+-----+---------+----------------+<br />
| rec_id          | int(11)  | NO   | PRI | NULL    | auto_increment |<br />
| device_id       | char(50) | YES  |     | NULL    |                |<br />
| type            | int(11)  | YES  |     | NULL    |                |<br />
| value           | char(50) | YES  |     | NULL    |                |<br />
| date            | datetime | YES  | MUL | NULL    |                |<br />
| unit_of_measure | char(1)  | YES  |     | NULL    |                |<br />
| device_desc     | char(50) | YES  |     | NULL    |                |<br />
+-----------------+----------+------+-----+---------+----------------+<br />
<br />
[sensor_logs]&gt; SELECT * FROM telemetry_log  ORDER BY date DESC Limit 10;<br />
+--------+-----------+------+-------+---------------------+-----------------+------------------+<br />
| rec_id | device_id | type | value | date                | unit_of_measure | device_desc      |<br />
+--------+-----------+------+-------+---------------------+-----------------+------------------+<br />
|  38548 | 72        |    3 | 70.2  | 2020-07-01 10:00:11 | F               | NULL             |<br />
|  38547 | 72        |    5 | 52.77 | 2020-07-01 10:00:11 | %               | NULL             |<br />
|  38546 | 72        |    5 | 52.77 | 2020-07-01 09:59:45 | %               | BondBack         |<br />
|  38545 | 13        |    6 | 3.00  | 2020-07-01 09:58:52 | V               | Compressor       |<br />
|  38544 | 13        |    3 | 88.36 | 2020-07-01 09:58:52 | F               | Compressor       |<br />
|  38543 | 11        |    3 | 71.02 | 2020-07-01 09:57:41 | F               | PaaRoomByFreezer |<br />
|  38542 | 11        |    5 | 58.63 | 2020-07-01 09:57:41 | %               | PaaRoomByFreezer |<br />
|  38541 | 30        |    3 | 70.54 | 2020-07-01 09:57:41 | F               | BondFront        |<br />
|  38540 | 30        |    5 | 52.50 | 2020-07-01 09:57:41 | %               | BondFront        |<br />
|  38539 | 71        |    3 | 72.5  | 2020-07-01 09:57:41 | F               | PaaNewRoom       |<br />
+--------+-----------+------+-------+---------------------+-----------------+------------------+]]></description>
            <dc:creator>Shawn Logan</dc:creator>
            <category>Triggers</category>
            <pubDate>Wed, 15 Jul 2020 17:02:28 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?99,688537,688537#msg-688537</guid>
            <title>INSERT INTO on AFTER UPDATE trigger (6 replies)</title>
            <link>https://forums.mysql.com/read.php?99,688537,688537#msg-688537</link>
            <description><![CDATA[ I need to append a record into a row_change table for each AFTER UPDATE event trigger. I get an error on the last END statement. Why?<br />
<br />
CREATE DEFINER = CURRENT_USER TRIGGER `hto_demo`.`field_AFTER_UPDATE` AFTER UPDATE ON `field` FOR EACH ROW<br />
BEGIN<br />
INSERT INTO row_change <br />
		(RowID, TableCd, FieldID, ChangeDateTime, RecordCreatedBit , DataBefore,DataAfter,UserID)<br />
	select<br />
		new.RowID <br />
		,&#039;FLD&#039;<br />
		,&#039;110&#039;<br />
		,Getdate()<br />
		,0<br />
		,old.FieldID<br />
		,new.FieldID<br />
		,system_user()<br />
        from field<br />
END <br />
<br />
Thank you]]></description>
            <dc:creator>JK Heydt</dc:creator>
            <category>Triggers</category>
            <pubDate>Fri, 26 Jun 2020 20:54:03 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?99,688241,688241#msg-688241</guid>
            <title>mySQL trigger on record that creates a new table (5 replies)</title>
            <link>https://forums.mysql.com/read.php?99,688241,688241#msg-688241</link>
            <description><![CDATA[ It&#039;s been quite a few years since I have done DB work. MySql backend (thru workbench) and I am using MS Access as a frontend.<br />
<br />
I have a base table that I am multilinking (basically a name column, and # of months column). Through a form, the table is updated (a record added) and I want that new record to trigger an event that creates a table and that table is named based on what the user inputted in the form/record, and create columns for the months - just named month1, month2, etc.<br />
<br />
Any thoughts on how to do this?  Any thoughts on a better way to do this? lol<br />
<br />
I am also looking for recommended reads/videos to get me back up to speed.<br />
Thanks!]]></description>
            <dc:creator>Mike F</dc:creator>
            <category>Triggers</category>
            <pubDate>Fri, 12 Jun 2020 20:49:46 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?99,688160,688160#msg-688160</guid>
            <title>MySQL triggers (1 reply)</title>
            <link>https://forums.mysql.com/read.php?99,688160,688160#msg-688160</link>
            <description><![CDATA[ Can someone please give me an example showing how and where to put a trigger into a MySQL 8 database?  All the tutorials seem to forget that we duma**s don&#039;t know where the description goes.  Just one complete example, please?<br />
<br />
Thanks,<br />
Jim Sawyer]]></description>
            <dc:creator>Jim Sawyer</dc:creator>
            <category>Triggers</category>
            <pubDate>Mon, 08 Jun 2020 21:27:28 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?99,687903,687903#msg-687903</guid>
            <title>Trigger to limit number of rows in another table (5 replies)</title>
            <link>https://forums.mysql.com/read.php?99,687903,687903#msg-687903</link>
            <description><![CDATA[ Can you help me with 2 triggers on 2 tables?<br />
I have Table1 that is having fields:<br />
ID<br />
MaxNumberOfRowsTable2<br />
UserID<br />
<br />
Table2 with fields:<br />
ID<br />
Name<br />
UserID<br />
<br />
I need to create a trigger on Table1 that will fire every time I change a field MaxNumberOfRowsTable2 and delete all extra rows in Table2 ordered by ID.<br />
<br />
For example if Table2 is having 100 rows and we change the MaxNumberOfRowsTable2 field in Table1 to value 15, the trigger should delete all the rows in Table2 and only leave the 15 oldest records.<br />
Can anyone help me with this trigger?<br />
<br />
Thanks,<br />
Davor]]></description>
            <dc:creator>Davor Geci</dc:creator>
            <category>Triggers</category>
            <pubDate>Tue, 26 May 2020 19:10:29 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?99,687392,687392#msg-687392</guid>
            <title>Need help creating mysql trigger (10 replies)</title>
            <link>https://forums.mysql.com/read.php?99,687392,687392#msg-687392</link>
            <description><![CDATA[ I&#039;m new to using triggers and really not sure how to proceed. I have an access table that a row is inserted whenever someone opens the website or downloads a file with the following structure:<br />
<br />
  `ID` int(5) NOT NULL autoincrement,<br />
  `LOG_TIME` datetime NOT NULL DEFAULT current_timestamp(),<br />
  `IP_ADDRESS` int(64) unsigned COLLATE utf8_general_mysql500_ci NOT NULL,<br />
  `FILENAME` varchar(50) COLLATE utf8_general_mysql500_ci DEFAULT NULL,<br />
    `country` varchar(50) COLLATE utf8_general_mysql500_ci DEFAULT NULL,<br />
    `area` varchar(50) COLLATE utf8_general_mysql500_ci DEFAULT NULL,<br />
    `city` varchar(50) COLLATE utf8_general_mysql500_ci DEFAULT NULL<br />
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_mysql500_ci;<br />
<br />
When the site is accessed, a row is inserted with only the first 3 fields are filled. When a file is downloaded another row is inserted with the first 4 fields filled. I want to create a trigger such that when a download row is inserted, the IP_ADDRESS is compared to another table to update the country, area, and city fields. I can currently do that for the whole table in mysql monitor using the following code:<br />
<br />
Update  access t2, ip_lookup t1 set t2.country = t1.country, t2.area = t1.area, t2.city = t1.city <br />
WHERE ((t2.IP_ADDRESS) BETWEEN (t1.start_ip) AND (t1.end_ip)) AND  t2.FILENAME is not null and t2.country is null;<br />
<br />
<br />
How would I write an &quot;after insert&quot; trigger to update the last 3 fields based on the ip of the row that was inserted because of a download?]]></description>
            <dc:creator>Larry Hale</dc:creator>
            <category>Triggers</category>
            <pubDate>Sat, 09 May 2020 16:20:13 +0000</pubDate>
        </item>
    </channel>
</rss>
