<?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>http://forums.mysql.com/list.php?99</link>
        <lastBuildDate>Tue, 21 May 2013 20:20:23 +0000</lastBuildDate>
        <generator>Phorum 5.2.19</generator>
        <item>
            <guid>http://forums.mysql.com/read.php?99,584133,584133#msg-584133</guid>
            <title>Adding two different Event triggers for the same table (3 replies)</title>
            <link>http://forums.mysql.com/read.php?99,584133,584133#msg-584133</link>
            <description><![CDATA[ I creates a &quot;Before Insert&quot; and &quot;before Update&quot; trigger on a table.But only one trigger is firing.To be more specific Only the last added trigger is firing. Example : table has three columns (a,B,c) and A is the primary Key column. I have to write trigger which will auto populate A using values in B and C. So i need both &quot;before insert&quot; and &quot;before update&quot; triggers. Can you guys give me help on this. I'm using MySQL workbench.]]></description>
            <dc:creator>sushaanth srirangapathi</dc:creator>
            <category>Triggers</category>
            <pubDate>Fri, 26 Apr 2013 03:54:39 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?99,581799,581799#msg-581799</guid>
            <title>trigger gets automatically deleted (2 replies)</title>
            <link>http://forums.mysql.com/read.php?99,581799,581799#msg-581799</link>
            <description><![CDATA[ hi,<br />
<br />
I have created some trigger(most of before delete) but after few min all the triggers get automatically deleted, any suggestion will be appreciate.<br />
Thanks]]></description>
            <dc:creator>SK JASIMUL ISLAM</dc:creator>
            <category>Triggers</category>
            <pubDate>Tue, 26 Mar 2013 14:05:01 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?99,581762,581762#msg-581762</guid>
            <title>trigger wich select field from another DB (no replies)</title>
            <link>http://forums.mysql.com/read.php?99,581762,581762#msg-581762</link>
            <description><![CDATA[ In my after update trigger,a select from another DB return table `db`.`table` doesn't exists. I am sure that the DB and tables exists !<br />
<br />
Mysql 5.1<br />
2 DB, DB1 &amp; DB2<br />
<br />
when inserting record into a table of DB1, I need a value comming from a table of DB2<br />
so I use this code to ask for value<br />
<br />
SET inum = (SELECT num FROM `DB2`.`t1` WHERE indexNum = localIndex);<br />
<br />
The problem is that the &quot;DB2.t1 doesn't exists&quot; message.<br />
<br />
Tried with or without  Quotes is the same<br />
<br />
The SELECT perform OK when used outside Trigger<br />
<br />
What is the correct syntax for this command ? <br />
<br />
Thanks for your help]]></description>
            <dc:creator>Francis Goblet</dc:creator>
            <category>Triggers</category>
            <pubDate>Mon, 18 Mar 2013 21:32:41 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?99,580604,580604#msg-580604</guid>
            <title>The delete trigger not firing (1 reply)</title>
            <link>http://forums.mysql.com/read.php?99,580604,580604#msg-580604</link>
            <description><![CDATA[ The delete trigger not firing if deletion of a row initiated by on delete cascade.]]></description>
            <dc:creator>Thahir Pattanathel</dc:creator>
            <category>Triggers</category>
            <pubDate>Tue, 05 Mar 2013 16:21:31 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?99,578926,578926#msg-578926</guid>
            <title>Triggers are not working properly after converting code from SQL SERVER (1 reply)</title>
            <link>http://forums.mysql.com/read.php?99,578926,578926#msg-578926</link>
            <description><![CDATA[ I'm in the process of migrating Triggers from SQL Server to Mysql. Based on the Table created in SQL SERVER, Some of the columns are NULL until the User inputs info into table. When you run the table in SQL SERVER Actionid is auto-incremented and the rest of the fields do not let you put in erroneous information. However, I had to convert and migrate the SQL SERVER Trigger to MYSQL and although my table doesn't show any errors, when I run the table in MYSQL it is allowing me to put ANYTHING in the field and creating erroneous entries. <br />
<br />
Can someone Please look at my code and tell me where I am going wrong. I truly appreciate it.<br />
<br />
SQL SERVER TRIGGER:<br />
USE [a7itm]<br />
GO<br />
/****** Object:  Trigger [dbo].[tr_act_delete]    Script Date: 02/11/2013 06:45:58 ******/<br />
SET ANSI_NULLS ON<br />
GO<br />
SET QUOTED_IDENTIFIER ON<br />
GO<br />
CREATE TRIGGER [dbo].[tr_act_delete] ON [dbo].[tr_action]<br />
   FOR DELETE AS<br />
   DECLARE @id INTEGER, @attachments INTEGER<br />
   SELECT<br />
   @id = deleted.actionid, @attachments = deleted.attachments<br />
   FROM deleted<br />
       BEGIN<br />
        IF @attachments &gt; 0<br />
        BEGIN<br />
            DELETE FROM tr_link WHERE linkheaderid IN <br />
        (SELECT linkheaderid FROM tr_linkheader WHERE     parentclasstype='artemispm.trdo.TRAction' AND parentid=@id)<br />
            DELETE FROM tr_linkheader WHERE parentclasstype='artemispm.trdo.TRAction' AND parentid=@id<br />
        END<br />
        DELETE FROM tr_comment WHERE parentclasstype='artemispm.trdo.TRAction' AND parentid=@id<br />
        DELETE FROM tr_alert WHERE parentclasstype='artemispm.trdo.TRAction' AND parentid=@id<br />
       END<br />
--------------------------------------------------------------<br />
MYSQL TRIGGER:<br />
<br />
USE `a7itm`;<br />
/****** Object:  Trigger [dbo].[tr_act_delete]    Script Date: 02/09/2013 17:12:24 ******/<br />
DROP TRIGGER IF EXISTS tr_act_delete;<br />
DELIMITER $$<br />
CREATE TRIGGER `tr_act_delete` AFTER DELETE ON `tr_action`<br />
   FOR EACH ROW BEGIN<br />
   DECLARE `id` INTEGER; <br />
   DECLARE `attachments` INTEGER;<br />
   SET<br />
   `id` =  deleted.actionid, `attachments` =  deleted.attachments;<br />
 <br />
      IF `attachments` &gt; 0 THEN<br />
		BEGIN<br />
         DELETE FROM tr_link WHERE linkheaderid IN <br />
         (SELECT linkheaderid FROM tr_linkheader WHERE parentclasstype='artemispm.trdo.TRAction' AND parentid=`id`);<br />
         DELETE FROM tr_linkheader WHERE parentclasstype='artemispm.trdo.TRAction' AND parentid=`id`;<br />
		END;<br />
         DELETE FROM tr_comment WHERE parentclasstype='artemispm.trdo.TRAction' AND parentid=`id`;<br />
         DELETE FROM tr_alert WHERE parentclasstype='artemispm.trdo.TRAction' AND parentid=`id`;<br />
       END IF;<br />
END$$<br />
DELIMITER ;]]></description>
            <dc:creator>tcee sutton</dc:creator>
            <category>Triggers</category>
            <pubDate>Tue, 05 Mar 2013 16:28:52 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?99,578751,578751#msg-578751</guid>
            <title>how to update a record (1 reply)</title>
            <link>http://forums.mysql.com/read.php?99,578751,578751#msg-578751</link>
            <description><![CDATA[ Hi when I executed an update statement to update a single record, my trigger update all records with the values of this record.<br />
<br />
Here is my trigger:<br />
<br />
DELIMITER $$<br />
 CREATE TRIGGER UPDATE_PRODUCT_ARTICLE_TRIGGER<br />
 AFTER UPDATE ON product_article<br />
 FOR EACH ROW BEGIN<br />
 update myisam_product_article<br />
 SET<br />
         product_id = NEW.product_id<br />
         AND a_desc = NEW.a_desc<br />
         AND header = NEW.header<br />
         AND parent_category_name = NEW.parent_category_name<br />
         AND sub_category_name = NEW.sub_category_name<br />
         AND postcode = NEW.postcode<br />
         AND latitude = NEW.latitude<br />
         AND longitude = NEW.longitude<br />
         AND creation_date = NEW.creation_date<br />
         AND suburb = NEW.suburb<br />
         AND state = NEW.state<br />
 WHERE article_id = NEW.article_id;<br />
 END$$<br />
 DELIMITER ;<br />
<br />
update sql statement used:<br />
<br />
update product_article set suburb=&quot;BLACKTOWN&quot; where postcode=&quot;2148&quot;;<br />
<br />
How to change my trigger for this case?<br />
<br />
Thanks<br />
Sam]]></description>
            <dc:creator>sam sam</dc:creator>
            <category>Triggers</category>
            <pubDate>Sat, 09 Feb 2013 19:09:50 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?99,578522,578522#msg-578522</guid>
            <title>mysqldump triggers (1 reply)</title>
            <link>http://forums.mysql.com/read.php?99,578522,578522#msg-578522</link>
            <description><![CDATA[ I am using mysqldump to do backups which include triggers and it results with the following delimiter syntax errors for the triggers:<br />
<br />
ERROR at line 1059: DELIMITER must be followed by a `delimiter` character or string<br />
<br />
ERROR 1064 (42000) at line 1060: You have an error with your SQL syntax; check the manual that corresponds to your MySQL server version from the right syntax to use near `` at line 5<br />
<br />
Line 1059 is this: DELIMITER ;;<br />
This is setting the delimiter before the trigger statments.<br />
<br />
The triggers were put in with DELIMITER $$. However, when backed up the resulting sql file has DELIMITER ;; instead of $$. Is there a way to make mysqldump output the original delimiters used to created the trigger?<br />
<br />
Thanks<br />
<br />
-r]]></description>
            <dc:creator>R Dydo</dc:creator>
            <category>Triggers</category>
            <pubDate>Sat, 09 Feb 2013 19:11:06 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?99,578153,578153#msg-578153</guid>
            <title>Dynamically Referencing OLD/NEW values? (4 replies)</title>
            <link>http://forums.mysql.com/read.php?99,578153,578153#msg-578153</link>
            <description><![CDATA[ I am a trigger newbie working on a trigger that will log table changes into a history table in xml format.  Basically when a row is updated, the old row gets written into an xml text field which is inserted into history_table.xml.<br />
<br />
CREATE TRIGGER history BEFORE UPDATE ON table1<br />
FOR EACH ROW<br />
BEGIN<br />
	DECLARE xmloutput TEXT;<br />
<br />
	SET xmloutput = concat(<br />
		&quot;&lt;field name=field1&gt;&quot;,OLD.field1,&quot;&lt;/field&gt;&quot;,<br />
		&quot;&lt;field name=field2&gt;&quot;,OLD.field2,&quot;&lt;/field&gt;&quot;<br />
		&quot;&lt;field name=field3&gt;&quot;,OLD.field3,&quot;&lt;/field&gt;&quot;<br />
		);<br />
<br />
	insert into `history_table` (`tableName`,`updated_by`,`xml`) values ('table1',NEW.updated_by,xmloutput);<br />
END<br />
<br />
To keep from having to write out each field in &quot;table1&quot; (some of these tables can contain over 100 fields) and to keep from having to drop/create a new trigger whenever columns are added/removed from &quot;table1&quot;, is it possible to loop through &quot;table1&quot; columns and reference the corresponding OLD/NEW values dynamically?<br />
<br />
Any help would be greatly appreciated.<br />
Thank You,<br />
Chad]]></description>
            <dc:creator>Chad Bachmeyer</dc:creator>
            <category>Triggers</category>
            <pubDate>Sat, 09 Feb 2013 19:06:59 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?99,577304,577304#msg-577304</guid>
            <title>Database Triggers (1 reply)</title>
            <link>http://forums.mysql.com/read.php?99,577304,577304#msg-577304</link>
            <description><![CDATA[ **<br />
Have created a trigger that on insert to ONE table triggers an insert to ANOTHER table.<br />
<br />
I want to include a value from the first table in a column of the second table.<br />
<br />
How do I do this ?]]></description>
            <dc:creator>Ken Ramkeesoon</dc:creator>
            <category>Triggers</category>
            <pubDate>Tue, 15 Jan 2013 09:49:06 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?99,577261,577261#msg-577261</guid>
            <title>How To Code This Trigger (1 reply)</title>
            <link>http://forums.mysql.com/read.php?99,577261,577261#msg-577261</link>
            <description><![CDATA[ Hi All,<br />
<br />
I'm wondering if someone can help me with coding a trigger based on the following code ? I'm a bit rusty with Triggers and this one is especially complicated for me. I've tried to simplify the code a bit with some generic terms. The basic idea of what I want to do is&gt;:<br />
<br />
IF (SELECT target_field1 FROM Database1.Table WHERE verificationfield1 = 'data') &lt;&gt;<br />
(SELECT target_field2 FROM Database2.Table WHERE verificationfield2 = 'data')<br />
THEN<br />
UPDATE Database1.Table<br />
SET target_field1 = (SELECT target_field2 FROM Database2.Table WHERE verificationfield2 = 'data')<br />
WHERE verificationfield1 = 'data'<br />
END IF;<br />
<br />
I'm looking to fire this trigger AFTER an UPDATE to the Database2.Table field. Any help would be tremendously appreciated.]]></description>
            <dc:creator>Chris Thompson</dc:creator>
            <category>Triggers</category>
            <pubDate>Tue, 15 Jan 2013 09:52:04 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?99,575457,575457#msg-575457</guid>
            <title>MYSQL triggers (8 replies)</title>
            <link>http://forums.mysql.com/read.php?99,575457,575457#msg-575457</link>
            <description><![CDATA[ Hello everybody<br />
<br />
First off all thank you for a great forum. I really appreciate all the help i get here.<br />
<br />
I have posted this code in another threat, but this question is slighty different. I have to make a trigger. The question sounds like this: <br />
&quot;Create a trigger that removes the season if unused whenever information about when and who produces a product is deleted (i.e., whenever a record is removed from the 'Produces' table, check if there are other records about product being produced for the same season, if not, remove also the corresponding record from the season table)&quot;<br />
<br />
the MYSQL code is here:<br />
<br />
CREATE TABLE IF NOT EXISTS Dvds(<br />
Serial integer NOT NULL,<br />
Name varchar(50),<br />
Year integer,<br />
Genre varchar(50),<br />
Price integer,<br />
PRIMARY KEY (Serial));<br />
<br />
CREATE TABLE IF NOT EXISTS Shops(<br />
Id integer NOT NULL,<br />
Name varchar(50),<br />
Address varchar(50),<br />
PRIMARY KEY (Id));<br />
<br />
CREATE TABLE IF NOT EXISTS Customers(<br />
CNo integer NOT NULL,<br />
AccNo integer,<br />
Time varchar(50),<br />
PRIMARY KEY (CNo));<br />
<br />
CREATE TABLE IF NOT EXISTS ContactPersons(<br />
Id integer NOT NULL,<br />
Name varchar(50),<br />
Phone integer,<br />
PRIMARY KEY (Id));<br />
<br />
CREATE TABLE IF NOT EXISTS Seasons(<br />
StartDate date NOT NULL,<br />
EndDate date NOT NULL,<br />
PRIMARY KEY (StartDate,EndDate));<br />
<br />
CREATE TABLE IF NOT EXISTS WebShops(<br />
Id integer NOT NULL,<br />
Url varchar(50),<br />
FOREIGN KEY (Id) REFERENCES Shops (Id),<br />
PRIMARY KEY (Id));<br />
<br />
CREATE TABLE IF NOT EXISTS Producer(<br />
Id integer NOT NULL,<br />
Address varchar(50),<br />
Name varchar(50),<br />
PRIMARY KEY (Id));<br />
<br />
CREATE TABLE IF NOT EXISTS Sold(<br />
Id integer NOT NULL,<br />
CNo integer NOT NULL,<br />
Serial integer NOT NULL,<br />
FOREIGN KEY (Id) REFERENCES Shops (Id),<br />
FOREIGN KEY (CNo) REFERENCES Customers (CNo),<br />
FOREIGN KEY (Serial) REFERENCES Dvds (Serial),<br />
PRIMARY KEY (Id,CNo,Serial));<br />
<br />
CREATE TABLE IF NOT EXISTS Has(<br />
Id integer NOT NULL,<br />
Serial integer NOT NULL,<br />
FOREIGN KEY (Id) REFERENCES Shops (Id),<br />
FOREIGN KEY (Serial) REFERENCES Dvds (Serial),<br />
PRIMARY KEY (Id,Serial));<br />
<br />
CREATE TABLE IF NOT EXISTS Has2(<br />
Serial integer NOT NULL,<br />
Producer_Id integer NOT NULL,<br />
StartDate date NOT NULL,<br />
EndDate date NOT NULL,<br />
ContactPersons_Id integer NOT NULL,<br />
FOREIGN KEY (Serial) REFERENCES Dvds (Serial),<br />
FOREIGN KEY ( Producer_Id) REFERENCES Producer (Id),<br />
FOREIGN KEY (StartDate) REFERENCES Seasons (StartDate),<br />
FOREIGN KEY (EndDate) REFERENCES Seasons (EndDate),<br />
FOREIGN KEY (ContactPersons_Id) REFERENCES ContactPersons (Id),<br />
PRIMARY KEY (Serial,Producer_Id,StartDate,EndDate,ContactPersons_Id));<br />
<br />
I have a feeling of it is something like this:<br />
<br />
CREATE TRIGGER `Seasons_before_delete` <br />
AFTER DELETE ON `Seasons`<br />
FOR EACH ROW <br />
BEGIN<br />
DELETE FROM seasonstart<br />
WHERE seasonstart.???????<br />
DELETE FROM seasonend<br />
WHERE seasonend.??????<br />
END<br />
<br />
but i really dont know. My teacher told me that i could use &quot;IF&quot; , ELSEIF, GOTOEND? But am i on the right track? Im really blank right now what to do, so hope someone have a suggestion, what i could do to solve this?<br />
<br />
Best Regards<br />
Mads]]></description>
            <dc:creator>Mads Kristensen</dc:creator>
            <category>Triggers</category>
            <pubDate>Fri, 07 Dec 2012 12:50:33 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?99,574977,574977#msg-574977</guid>
            <title>1442 - Can't update table (1 reply)</title>
            <link>http://forums.mysql.com/read.php?99,574977,574977#msg-574977</link>
            <description><![CDATA[ I've got this trigger:<br />
<br />
CREATE DEFINER =  `root`@`localhost` TRIGGER `ograniczenie` BEFORE INSERT ON `wyjscia` <br />
FOR EACH ROW<br />
BEGIN <br />
SELECT COUNT( * ) INTO @cnt FROM wyjscia;<br />
IF @cnt &gt;=5 THEN <br />
DELETE FROM wyjscia WHERE id = ((SELECT MIN(id) FROM wyjscia)) LIMIT 1 ;<br />
END IF ;<br />
END<br />
<br />
Error: #1442 - Can't update table 'wyjscia' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.<br />
<br />
Is there any solution of this problem? :(]]></description>
            <dc:creator>Tomasz Adamczyk</dc:creator>
            <category>Triggers</category>
            <pubDate>Sat, 01 Dec 2012 22:09:48 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?99,573445,573445#msg-573445</guid>
            <title>ERROR 1442 - Cannot update table which has trigger (2 replies)</title>
            <link>http://forums.mysql.com/read.php?99,573445,573445#msg-573445</link>
            <description><![CDATA[ The problem is like in a title, Ive read some solutions and used &quot;NEW.colum_name&quot; keyword to solve the problem. Trigger definition:<br />
<br />
CREATE TRIGGER `trigger1` BEFORE UPDATE ON `driver`<br />
 FOR EACH ROW BEGIN<br />
UPDATE driver<br />
SET NEW.is_available=0<br />
WHERE NEW.break_finish_time &gt;= now() &amp;&amp; NEW.break_start_time &lt;= now();<br />
END<br />
<br />
And when I want to update table 'driver':<br />
<br />
ERROR 1442: Can't update table 'driver' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.<br />
SQL Statement:<br />
UPDATE `taxi`.`driver` SET `break_finish_time`='2012-11-09 12:13:00' WHERE `iddriver`='2'<br />
<br />
<br />
<br />
'driver' create statement:<br />
<br />
================================================================<br />
delimiter $$<br />
<br />
CREATE<br />
DEFINER=`root`@`localhost`<br />
TRIGGER `taxi`.`trigger1`<br />
BEFORE UPDATE ON `taxi`.`driver`<br />
FOR EACH ROW<br />
BEGIN<br />
UPDATE driver<br />
SET NEW.is_available=0<br />
WHERE NEW.break_finish_time &gt;= now() &amp;&amp; NEW.break_start_time &lt;= now();<br />
END<br />
$$<br />
<br />
CREATE TABLE `driver` (<br />
  `iddriver` int(10) unsigned NOT NULL AUTO_INCREMENT,<br />
  `is_available` tinyint(1) NOT NULL,<br />
  `driver_name` varchar(45) COLLATE utf8_polish_ci NOT NULL,<br />
  `driver_surname` varchar(45) COLLATE utf8_polish_ci NOT NULL,<br />
  `driverpoint_horizontal` double NOT NULL,<br />
  `driverpoint_vertical` double NOT NULL,<br />
  `break_start_time` timestamp NULL DEFAULT NULL,<br />
  `break_finish_time` timestamp NULL DEFAULT NULL,<br />
  PRIMARY KEY (`iddriver`)<br />
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci$$<br />
================================================================<br />
<br />
It doesnt have any foreign keys, however other tables does have foreign key which uses 'iddriver' from 'driver' table.<br />
<br />
Is there any solution?]]></description>
            <dc:creator>Daniel Xyz</dc:creator>
            <category>Triggers</category>
            <pubDate>Sun, 18 Nov 2012 13:26:31 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?99,572956,572956#msg-572956</guid>
            <title>Trigger for deleting rows by checking the length of dynamically created table size (no replies)</title>
            <link>http://forums.mysql.com/read.php?99,572956,572956#msg-572956</link>
            <description><![CDATA[ I have a fixed length table(purchased) which is updated by a dynamically created table(cart).<br />
i want to give a trigger to purchased in such a way that if the purchased table length meets its maximum size it should delete the oldest data in it to let insert the new data.<br />
I'm stuck at the point of how many rows to delete before inserting into the table, because i will be copying the whole contents of cart table which is created dynamically, whose size is unpredictable.<br />
any help would be appreciated]]></description>
            <dc:creator>Preethi K</dc:creator>
            <category>Triggers</category>
            <pubDate>Mon, 05 Nov 2012 06:27:29 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?99,571925,571925#msg-571925</guid>
            <title>Need Help with TRIGGER and IF (3 replies)</title>
            <link>http://forums.mysql.com/read.php?99,571925,571925#msg-571925</link>
            <description><![CDATA[ I have a PHP app that inserts 'Pass', 'Fail' or 'NA' into fields TEST1, TEST2, TEST3... through TEST15.<br />
<br />
I have a field called OVERALL that needs to be automatically updated with 'FAIL' if any of the TEST1-TEST15 fields contains 'Fail'.<br />
<br />
I'm pretty sure I need to use a trigger containing the update statement and either CASE or IF, but I haven't been able to nail down the exact syntax.<br />
<br />
Can anyone please help a MySQL noob? I'm using MySQL Server version: 5.1.63-0+squeeze1 (Debian).]]></description>
            <dc:creator>James House</dc:creator>
            <category>Triggers</category>
            <pubDate>Tue, 23 Oct 2012 21:58:27 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?99,570455,570455#msg-570455</guid>
            <title>Trigger Problem (1 reply)</title>
            <link>http://forums.mysql.com/read.php?99,570455,570455#msg-570455</link>
            <description><![CDATA[ I tryed to create this trigger with PHPMyAdmin and MySQL Server (5.1.54-rel12.6-log).<br />
And PHPMyAdmin tell me a success.<br />
But when i list all the Trigger, there is nothing!<br />
x.X<br />
<br />
DELIMITER $$<br />
<br />
DROP TRIGGER IF EXISTS auChecarPosicao;<br />
CREATE TRIGGER auChecarPosicao<br />
AFTER UPDATE ON com_orcamento_det<br />
FOR EACH ROW<br />
BEGIN<br />
	SET @_result = 0;<br />
	<br />
	IF(OLD.orcd_situacao &lt;&gt; NEW.orcd_situacao AND NEW.orcd_situacao &lt;&gt; 6 AND NEW.orcd_situacao &lt;&gt; 5)<br />
	THEN<br />
		SELECT orcc_id_posicao INTO @pos<br />
		FROM com_orcamento_cab<br />
		WHERE orcc_id_orcamento = NEW.orcd_id_orc_cab<br />
		AND orcc_id_revisao = NEW.orcd_id_orc_cab_revisao;<br />
				<br />
		IF(@pos = 1)<br />
		THEN<br />
			IF(NEW.orcd_situacao &lt;&gt; 1 OR NEW.orcd_situacao &lt;&gt; 11)<br />
			THEN<br />
				SET @_result = 3;<br />
			END IF;<br />
		ELSE IF (@pos = 17)<br />
		THEN<br />
			SET @_result = 3;<br />
			<br />
			IF(NEW.orcd_situacao = 17)<br />
			THEN<br />
				SELECT count(orcd_situacao) INTO @res<br />
				FROM com_orcamento_det<br />
				WHERE orcd_id_orc_cab = NEW.orcd_id_orc_cab<br />
				AND orcd_id_orc_cab_revisao = NEW.orcd_id_orc_cab_revisao<br />
				AND orcd_situacao &lt;&gt; 17;<br />
				<br />
				IF(@res = 0)<br />
				THEN<br />
					SET @_result = 17;<br />
				END IF;<br />
			END IF;<br />
		END IF;<br />
	END IF;<br />
	<br />
	IF(@_result &lt;&gt; 0)<br />
	THEN<br />
		UPDATE com_orcamento_cab<br />
		SET orcc_id_posicao = @_result<br />
		WHERE orcc_id_orcamento = NEW.orcd_id_orc_cab<br />
		AND orcc_id_revisao = NEW.orcd_id_orc_cab_revisao;<br />
	END IF;<br />
END $$ DELIMITER ;]]></description>
            <dc:creator>José Maia Neto</dc:creator>
            <category>Triggers</category>
            <pubDate>Tue, 23 Oct 2012 17:52:00 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?99,569399,569399#msg-569399</guid>
            <title>after insert trigger problem (no replies)</title>
            <link>http://forums.mysql.com/read.php?99,569399,569399#msg-569399</link>
            <description><![CDATA[ hi, i'm new with mysql and i have a problem that i don't undertand what happend.<br />
i'm using mysql workbench 5.2.37<br />
thats what i've done<br />
<br />
delimiter [;<br />
create trigger trans_back_up1<br />
after insert on trans_tabla1<br />
for each row <br />
begin<br />
delete from trans_tabla_inter;<br />
insert into trans_tabla_inter(nombre_tabla) values ('trans_tabla1');<br />
end;<br />
[;<br />
<br />
delimiter [;<br />
create trigger trans_back_up2<br />
after insert on trans_tabla_inter<br />
for each row<br />
begin<br />
insert into trans_tabla_back_up<br />
       select * <br />
       from trans_tabla1;<br />
end;<br />
[;<br />
<br />
the problem is that when i insert into trans_tabla1, 5 rows from a file, i have the 5 rows fine on trans_tabla1 but on the table trans_tabla_back_up i have duplicates, i have 5 copies of the first row, 4 copies of the second, 3 of the third, 2 of the fourth , and 1 of the fifth.<br />
<br />
<br />
can someone tell me where is the error]]></description>
            <dc:creator>diego hernandez</dc:creator>
            <category>Triggers</category>
            <pubDate>Mon, 24 Sep 2012 16:43:34 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?99,569311,569311#msg-569311</guid>
            <title>Trigger (1 reply)</title>
            <link>http://forums.mysql.com/read.php?99,569311,569311#msg-569311</link>
            <description><![CDATA[ Hello, i have problem when i create trigger. I have a table name &quot;request&quot;. and i want to check record when new record is inserted. The &quot;request&quot; table has a column named &quot;number&quot;. if record has negative value for number column, i want to dismiss the insert statement. <br />
Help me.]]></description>
            <dc:creator>Jijgee Jamsran</dc:creator>
            <category>Triggers</category>
            <pubDate>Tue, 25 Sep 2012 06:50:21 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?99,569224,569224#msg-569224</guid>
            <title>Want to create trigger on mysql 5.0.45 with IF NOT EXISTS (2 replies)</title>
            <link>http://forums.mysql.com/read.php?99,569224,569224#msg-569224</link>
            <description><![CDATA[ I have tried to create trigger on mysql 5.0.45 but it will give error.Same trigger I have successfully created on mysql 5.1.61.<br />
<br />
My requirement is, I have two databases and I want to insert into one database table after insert of other database table and also vice a verse.<br />
<br />
My trigger is <br />
<br />
<pre class="bbcode">DELIMITER $$
CREATE DEFINER=root@localhost TRIGGER trigeer_with_if AFTER insert ON `test_new`.employees
FOR EACH ROW
Begin
	If NOT EXISTS(SELECT employeeNumber FROM `test_db`. employees WHERE employeeNumber = NEW.employeeNumber) THEN
	INSERT INTO `test_db`. employees VALUES (NEW.employeeNumber,NEW.lastName,NEW.firstName,substr(NEW.extension,0,LENGTH(NEW.extension)-2),NEW.email,NEW.officeCode,NEW.reportsTo,NEW.jobTitle);
	end if;

END$$
DELIMITER ;</pre>
<br />
But I have tried to create this trigger though phpmyadmin on mysql 5.0.45 it will gives me below error:<br />
<br />
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DELIMITER $$<br />
CREATE DEFINER=root@localhost TRIGGER trigeer_with_if AFTER insert' at line 1 <br />
<br />
I am new to trigger, so don't know how to resolve this problem.<br />
<br />
Thanks,<br />
Pkachhia]]></description>
            <dc:creator>Prashesh Kachhia</dc:creator>
            <category>Triggers</category>
            <pubDate>Tue, 25 Sep 2012 06:05:48 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?99,569212,569212#msg-569212</guid>
            <title>Creating a payroll profile out of a new employee record (no replies)</title>
            <link>http://forums.mysql.com/read.php?99,569212,569212#msg-569212</link>
            <description><![CDATA[ Structure:<br />
employee - employee_id, employee_name, pin_no<br />
payroll - employee_id, pay_period, gross_income<br />
<pre class="bbcode">
-- Trigger DDL Statements
DELIMITER $$

USE `edica`$$
CREATE TRIGGER CreatePayrollProfile
   AFTER INSERT ON employee
   FOR EACH STATEMENT
     INSERT INTO payroll
         VALUES (employee.employee_id,
                 '2012-2-30',
                 '0.00');</pre>
<br />
There is an error on FOR EACH STATEMENT. Just a red cross on the left.<br />
And If I want to trace the pay_period, do I open up another table containing this info driven by the user?<br />
Thanks<br />
Jack]]></description>
            <dc:creator>Jack Luk</dc:creator>
            <category>Triggers</category>
            <pubDate>Sat, 22 Sep 2012 09:22:15 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?99,568782,568782#msg-568782</guid>
            <title>trigger Throw error message (1 reply)</title>
            <link>http://forums.mysql.com/read.php?99,568782,568782#msg-568782</link>
            <description><![CDATA[ i need a trigger to give an error message if invalid data is inserted.here is my trial and its not working. please help on error handling in mysql. thank you.<br />
<br />
mysql&gt; DELIMITER //<br />
mysql&gt;  CREATE TRIGGER TR_CHECKCONSTRAINT<br />
    -&gt;   BEFORE INSERT ON TEST_CHECKCO<br />
    -&gt;  FOR EACH ROW<br />
    -&gt;  BEGIN<br />
    -&gt;  DECLARE msg varchar(255);<br />
    -&gt;  IF NOT new.AGE = 50 THEN<br />
    -&gt;  SET msg = 'INVALID DATA'<br />
    -&gt;  SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = msg;<br />
    -&gt;  END IF;<br />
    -&gt; END<br />
    -&gt; //]]></description>
            <dc:creator>natukunda liz</dc:creator>
            <category>Triggers</category>
            <pubDate>Tue, 18 Sep 2012 06:41:10 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?99,568303,568303#msg-568303</guid>
            <title>MySQL Trigger performance (no replies)</title>
            <link>http://forums.mysql.com/read.php?99,568303,568303#msg-568303</link>
            <description><![CDATA[ I am relatively new to MySQL and worked on Oracle previously.<br />
<br />
I wanted to know if anyone worked significantly with triggers on MySQL and have any benchmarks for its performance . Have anyone had experience where triggers made the inserts, updates, deletes very slow, becoming a bottle neck or bringing down the server?]]></description>
            <dc:creator>Venkat Ram Santosh</dc:creator>
            <category>Triggers</category>
            <pubDate>Wed, 12 Sep 2012 18:44:20 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?99,568201,568201#msg-568201</guid>
            <title>Can't create the trigger i always get an error. (1 reply)</title>
            <link>http://forums.mysql.com/read.php?99,568201,568201#msg-568201</link>
            <description><![CDATA[ Hello guys, Im new here and i have never used triggers in Mysql, this is the first time, and im having problems migrating one trigger from sql server to mysql, i always get an error when i try to create it, this is the trigger im trying to create in mysql:<br />
<br />
create trigger insertarAccesos after insert on perfil<br />
for each row begin<br />
declare @Perfil varchar(30),<br />
set @Perfil = (Select idPerfil from perfil),<br />
insert into Acceso values(@Perfil,0,0,0,0,0,0,0)<br />
end;<br />
<br />
And it says i have some problems with te sintax, can anyone help me please?  thanks in advance.]]></description>
            <dc:creator>Jorge Diaz</dc:creator>
            <category>Triggers</category>
            <pubDate>Wed, 12 Sep 2012 20:17:09 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?99,568156,568156#msg-568156</guid>
            <title>Problem with Trigger (2 replies)</title>
            <link>http://forums.mysql.com/read.php?99,568156,568156#msg-568156</link>
            <description><![CDATA[ Hello,<br />
<br />
i have a little problem with my trigger.<br />
i created a trigger:<br />
<br />
BEGIN<br />
<br />
IF((SELECT `Wert` FROM parameter_history WHERE `BusNr` = NEW.BusNr AND `MesswertNr` = NEW.MesswertNr ORDER BY `Timestamp` DESC LIMIT 1) != NEW.Value)<br />
THEN<br />
  INSERT INTO parameter_history (`BusNr`, `MesswertNr`, `Value`) VALUES (NEW.BusNr, NEW.MesswertNr, NEW.Value);<br />
END IF;<br />
<br />
END<br />
<br />
The event of the trigger is after an update.<br />
if there is already a &quot;New.Value&quot; it works really good.<br />
but if there is no &quot;New.Value&quot; in my database it doesn`t work and i don`t know why. <br />
The problem is, that i can`t get a value back from &quot;NEW.Value&quot; when there is actually no entry in my table.<br />
<br />
Can anybody help me?<br />
<br />
kind regards]]></description>
            <dc:creator>Reinhard Windpassinger</dc:creator>
            <category>Triggers</category>
            <pubDate>Wed, 12 Sep 2012 20:21:28 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?99,566744,566744#msg-566744</guid>
            <title>syntax (1 reply)</title>
            <link>http://forums.mysql.com/read.php?99,566744,566744#msg-566744</link>
            <description><![CDATA[ Hi <br />
what wong's with this syntax? <br />
It hightlight the last 2 lines not correct, I wonder if this is the &quot;;&quot; ...<br />
Thanks<br />
<br />
CREATE TRIGGER UPD_INTEGRAL_NO BEFORE INSERT ON mt4.mt4_trades<br />
FOR EACH ROW <br />
    IF INSTR(BINARY new.comment,'O:') &gt;0 THEN<br />
        SET NEW.INTEGRAL_OPEN = MID(new.comment,INSTR(BINARY new.comment,'O:')+2,8);<br />
    END IF;]]></description>
            <dc:creator>Marco Chan</dc:creator>
            <category>Triggers</category>
            <pubDate>Fri, 31 Aug 2012 12:08:14 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?99,566093,566093#msg-566093</guid>
            <title>Is it possible to delete record after selecting it? (1 reply)</title>
            <link>http://forums.mysql.com/read.php?99,566093,566093#msg-566093</link>
            <description><![CDATA[ Hello. Is it possible to create trigger which would delete record after selecting that record with SELECT * ... query?]]></description>
            <dc:creator>Yazaki NA</dc:creator>
            <category>Triggers</category>
            <pubDate>Wed, 29 Aug 2012 07:28:36 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?99,566040,566040#msg-566040</guid>
            <title>collision with auto_increment &amp; triggers across threads (no replies)</title>
            <link>http://forums.mysql.com/read.php?99,566040,566040#msg-566040</link>
            <description><![CDATA[ DB : MySQL 5.5.23, InnoDB (Amazon RDS installation)<br />
<br />
I Have a DB with separate tables for payments, credits and charges, with a master transaction table to keep them all in correct order between them all. This was recently moved from Oracle where I used one sequence to generate the transaction ids across all the payments, credits, charges tables.<br />
<br />
For MySQL, I have had to change this around since auto_increments work slightly differently.<br />
<br />
I have an auto_increment field on my transaction master table, and a trigger to generate the transaction ID based upon that on a before insert. These transaction ids are then the PK in the charge, credit &amp; payment tables.<br />
<br />
<pre class="bbcode">
+----------------+---------------------+------+-----+---------+----------------+
| Field          | Type                | Null | Key | Default | Extra          |
+----------------+---------------------+------+-----+---------+----------------+
| iid            | bigint(20)          | NO   | PRI | NULL    | auto_increment |
| member_id      | varchar(20)         | NO   | MUL | NULL    |                |
| transaction_id | varchar(20)         | NO   |     | NULL    |                |
| timestamp      | datetime            | NO   | PRI | NULL    |                |
| currency       | tinyint(3) unsigned | NO   |     | NULL    |                |
+----------------+---------------------+------+-----+---------+----------------+

(the timestamp field is part of the primary key as it is partitioned by date)

create trigger trg_i_usa_transactions
before insert on usa_transactions
for each row
begin
  if length(new.transaction_id) = 4 then
    set new.transaction_id = (
        select concat(new.transaction_id, lpad(cast(auto_increment as char), 12, '0'))
        from information_schema.tables
        where table_schema = database() and table_name = 'usa_transactions'
    );
  end if;
end$$</pre>
<br />
Now, I have stored procedures for creating the payments, charges and credits that, after some sanity and business rule checks, generates an id via :<br />
<br />
<pre class="bbcode">
        insert into usa_transactions (
            member_id, transaction_id, timestamp, currency
        )
        values (
            memberid, 'USAG', timestamp, 1
        );

        select t.transaction_id 
        into chargeid
        from usa_transactions t
        where t.iid = last_insert_id();</pre>
<br />
Each transaction type has their own prefix (legacy system, that's how it was designed, not important etc).<br />
<br />
So, theoretically, for every row of the usa_transactions table, the generated transaction id should have the auto_increment value as part of it.<br />
<br />
Unfortunately, that is not happening if 2 different threads try to do an insert into the usa_transactions table at the same time.<br />
<br />
<pre class="bbcode">
+----------+---------------+------------------+---------------------+----------+
| iid      | member_id     | transaction_id   | timestamp           | currency |
+----------+---------------+------------------+---------------------+----------+
| 97988555 | USAC000054506 | USAG000097988555 | 2012-08-24 00:53:00 |        1 |
| 97988556 | USAC000054506 | USAD000097988556 | 2012-08-24 00:53:00 |        0 |
| 97988557 | USAC000057181 | USAG000097988557 | 2012-08-24 00:53:03 |        1 |
| 97988558 | USAC000012043 | USAD000097988557 | 2012-08-24 00:53:05 |        1 |
| 97988559 | USAC000012043 | USAG000097988559 | 2012-08-24 00:53:05 |        1 |
| 97988560 | USAC000057181 | USAD000097988559 | 2012-08-24 00:53:03 |        0 |
+----------+---------------+------------------+---------------------+----------+</pre>
<br />
Rows 1, 2, 3, 5 are correct, Row 4 has the transaction_id based off the previously inserted row. Row 6 has similar behaviour.<br />
<br />
The transactions were being created by two different processes on the same machine, neither sharing connections. One was a single-threaded standalone java app, the second was running under tomcat. Both have autocommit turned off.<br />
<br />
I have tested this quite a bit. When only one thread from anywhere is creating the transactions, they line up from iid --&gt; transaction_id. When another thread using a completely new connection starts to create its own transactions at the same time, that's when the problems occur. I was even able to duplicate it by doing the same inserts via a mysql client and bypassing the stored procedures.<br />
<br />
Is there something wrong with the trigger code or the way I am getting the generated record in the stored procedure? Is it a bug in this version of the DB engine? <br />
<br />
Help<br />
<br />
Thanks<br />
<br />
Chris]]></description>
            <dc:creator>Chris Cheshire</dc:creator>
            <category>Triggers</category>
            <pubDate>Fri, 24 Aug 2012 02:27:27 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?99,565722,565722#msg-565722</guid>
            <title>Tigger to Search String (4 replies)</title>
            <link>http://forums.mysql.com/read.php?99,565722,565722#msg-565722</link>
            <description><![CDATA[ Hello, im need help us. I have one field in database than have some data ( string). Under this string i have some integers. Its possible take just this integes and insert in other table? Ty for all]]></description>
            <dc:creator>Pedro Podclan</dc:creator>
            <category>Triggers</category>
            <pubDate>Thu, 30 Aug 2012 11:47:46 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?99,564195,564195#msg-564195</guid>
            <title>Trigger is not working (1 reply)</title>
            <link>http://forums.mysql.com/read.php?99,564195,564195#msg-564195</link>
            <description><![CDATA[ hello,<br />
I am creating a table and a TRIGGER so when I create/update a register, it calculates by itself.<br />
If I left &quot;blank&quot; the column that is to be calculated, I have an error &quot;1064&quot;<br />
<br />
------------------------------------------------------------<br />
delimiter $$<br />
<br />
CREATE TABLE res_pro_servicios (<br />
  id_servicio int(10) unsigned NOT NULL AUTO_INCREMENT,<br />
  id_proveedor_res int(10) unsigned DEFAULT NULL,<br />
  no_reservacion int(11) DEFAULT NULL,<br />
  servicio varchar(255) DEFAULT NULL,<br />
  descripcion varchar(255) DEFAULT NULL,<br />
  fecha date DEFAULT NULL,<br />
  subtotal decimal(10,2) DEFAULT '0.00',<br />
  iva decimal(10,2) DEFAULT '0.00',<br />
  total decimal(10,2) DEFAULT '0.00',<br />
  confirmar_cv01 set('si','no') NOT NULL DEFAULT 'no',<br />
  cancelado_cv01 set('si','no') NOT NULL DEFAULT 'no',<br />
  eliminado_hi01 set('si','no') NOT NULL DEFAULT 'no',<br />
  PRIMARY KEY (id_servicio)<br />
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE=utf8_spanish_ci$$<br />
<br />
<br />
CREATE TRIGGER calcula_iva_res_servicios<br />
BEFORE UPDATE ON res_pro_servicios<br />
FOR EACH ROW<br />
BEGIN<br />
    UPDATE res_pro_servicios<br />
        SET total = (NEW.subtotal*(NEW.iva/100))<br />
        WHERE id_servicio = NEW.id_servicio;<br />
END$$<br />
<br />
DELIMITER ;<br />
------------------------------------------------------------]]></description>
            <dc:creator>Marco Antonio Rios</dc:creator>
            <category>Triggers</category>
            <pubDate>Tue, 21 Aug 2012 04:57:57 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?99,563912,563912#msg-563912</guid>
            <title>Trigger to message an application (1 reply)</title>
            <link>http://forums.mysql.com/read.php?99,563912,563912#msg-563912</link>
            <description><![CDATA[ I know this probably comes up now and again, and i've searched and searched.  What I need to do is fire an event or send a message on inserts/updates/deletes for specific tables that will tell applications using the database to reload the data they have displayed.  I am using c# for the applications, and data is also inserted via php.<br />
<br />
There must be some common solution out there for this that I just don't see.  <br />
<br />
Technically, the application on the server only needs to see the message, then it could message the other systems on the LAN.]]></description>
            <dc:creator>patrick schomburg</dc:creator>
            <category>Triggers</category>
            <pubDate>Tue, 21 Aug 2012 04:59:51 +0000</pubDate>
        </item>
    </channel>
</rss>
