Home Category Table Mysql 5 Trigger Before Insert
Mysql 5 Trigger Before Insert PDF Print E-mail
Written by TBG   
Wednesday, 11 February 2009 19:25

This is an working example of a Before Insert Trigger with an If statement and modifying the incoming values.

-- Reset the Active Delimiter so the ; will not be executed when the trigger code is loaded
DELIMITER |

-- Create the Trigger
CREATE TRIGGER CreditCard_GiftCardNoEncrypt

BEFORE INSERT ON CreditCard
  FOR EACH ROW
    BEGIN
      IF (NEW.cardType !='GIFTCARD') THEN
        SET NEW.cardNumber = DES_ENCRYPT(NEW.cardNumber,'f8zz9');
      END IF;

      SET NEW.encrypted = 1;
    END
;
-- The Active Delimiter
|

-- Reset the Active Delimiter back to ;
DELIMITER ;

Last Updated on Wednesday, 11 February 2009 19:47
 
Banner
Copyright © 2010 The-Bravo-Group. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.