MySQL Forums
Forum List  »  Newbie

Re: How to fill fields with automatically
Posted by: Rieqy Erysya
Date: July 06, 2012 09:41AM

Initially, I created two fields. The first field is `hstring` I give LONGTEXT type, and the second field is `hash` and i give VARCHAR(32) type.
then I created a trigger to populate `hash` field with a value of `hstring` to be converted into MD5
*I did not make the primary key on one of the two columns because it will cause an error message like this
Duplicate entry '' for key 'PRIMARY'
I think so =))

and after that,,I make the code like this
CREATE TRIGGER `tr_insert_md5` AFTER INSERT ON `tbl_md5`
FOR EACH ROW
BEGIN
UPDATE `tbl_md5` SET NEW.`hash` = MD5(`hstring`) WHERE `hstring` = NEW.`hstring`;
END//
I don't know that the code is correct or incorrect :)) hehe

and after that again,,i fill the value on `hstring` with :
INSERT INTO `tbl_md5`(`string`) VALUES ('mbahmu');

but, that there is actually an error like this :
 Can't update table 'tbl_md5' in stored function/trigger because it is already used by statement which invoked this stored function/trigger

can you help me ?? Y_Y



Edited 1 time(s). Last edit at 07/06/2012 09:44AM by Rieqy Erysya.

Options: ReplyQuote




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.