MySQL Forums
Forum List  »  Triggers

How to use trigger to register user name who insert or modify a row of
Posted by: Cary Martin
Date: November 11, 2015 01:23PM

another user said that they would use this for using correct username in trigger:

SELECT SUBSTRING_INDEX(USER(),'@',1) from dual,

actually if you want to use it in a trigger, it has to be this:

SUBSTRING_INDEX(USER(),'@',1)

something like this...

delimiter $$
DROP TRIGGER IF EXISTS `upTrig`$$
CREATE TRIGGER `upTrig`
BEFORE UPDATE ON `table_data`
FOR EACH ROW
BEGIN
IF(OLD.inserted_by IS NOT NULL) THEN
SET NEW.modified_by = SUBSTRING_INDEX(USER(),'@',1);
END IF;
END $$
delimiter ;

Options: ReplyQuote


Subject
Views
Written By
Posted
How to use trigger to register user name who insert or modify a row of
1939
November 11, 2015 01:23PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.