dbTalk Databases Forums  

before update Trigger

comp.databases.mysql comp.databases.mysql


Discuss before update Trigger in the comp.databases.mysql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
manfred
 
Posts: n/a

Default before update Trigger - 12-31-2011 , 03:49 AM






Hallo,

have following problem:

I have to send an updated Row to a history table.


CREATE
DEFINER=`root`@`xxxxxxx`
TRIGGER `pp`.`buTrigger_Adresse`
BEFORE UPDATE ON `pp`.`t_adresse`
FOR EACH ROW
BEGIN

SET @iU = 0, @iDate = "1900.00.00 00.00.00";
-- sp converts user to userID and return timestamp
CALL sp_User2PersonID (@iU, @iDate);
SET NEW.modusr = @iU, NEW.moddate = @iDate;

INSERT INTO x_adresse (
SELECT *, NULL, @iU, NULL
FROM t_adresse
WHERE NEW.modusr = @iU AND NEW.moddate = @iDate );

END$$

--------------

the INSERT INTO x_adresse (.....) inserts ALL records from t_adress into
h_adress.
What have I to do that only the modivied row will be inserted???

best thanks for help.


BEST WISHES to ALL for 2012!!!

Reply With Quote
  #2  
Old   
Lennart Jonsson
 
Posts: n/a

Default Re: before update Trigger - 12-31-2011 , 06:07 AM






On 2011-12-31 10:49, manfred wrote:
Quote:
Hallo,

have following problem:

I have to send an updated Row to a history table.


CREATE
DEFINER=`root`@`xxxxxxx`
TRIGGER `pp`.`buTrigger_Adresse`
BEFORE UPDATE ON `pp`.`t_adresse`
FOR EACH ROW
BEGIN

SET @iU = 0, @iDate = "1900.00.00 00.00.00";
-- sp converts user to userID and return timestamp
CALL sp_User2PersonID (@iU, @iDate);
SET NEW.modusr = @iU, NEW.moddate = @iDate;

INSERT INTO x_adresse (
SELECT *, NULL, @iU, NULL
FROM t_adresse
WHERE NEW.modusr = @iU AND NEW.moddate = @iDate );

END$$

Something like:

BEGIN

insert into x_adresse (col_1, col_2, ..., col_n)
values (new.col_1, new.col_2, ..., new.col_n)

END

replace new.col_m with whatever constants you want to use

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.