phpmyadmin trigger code example

Example 1: Create Trigger in phpMyAdmin

delimiter //
CREATE TRIGGER before_insert_money BEFORE INSERT ON money
FOR EACH
ROW
BEGIN
    UPDATE accounts SET balance=10.0;
END;
//
delimiter ;

Example 2: Create Trigger in phpMyAdmin

delimiter $$
CREATE TRIGGER copy_pid AFTER INSERT on upload FOR EACH ROW 

BEGIN

INSERT INTO rating (uid,pid) VALUES (NEW.username,NEW.id);

END$$
delimiter ;

Example 3: Create Trigger in phpMyAdmin

CREATE TRIGGER nomCltInsert
BEFORE INSERT ON client
FOR EACH ROW
    UPDATE client
    SET
        NEW.NomClient = UPPER(NEW.NomClient),
        NEW.PrenomClient = CONCAT( UPPER( LEFT(NEW.PrenomClient,1) ) , LOWER( SUBSTR( NEW.PrenomClient,2 ) ) );
 
CREATE TRIGGER nomCltUpdate
BEFORE UPDATE ON client
FOR EACH ROW
    UPDATE client
    SET
        NEW.NomClient = UPPER(NEW.NomClient),
        NEW.PrenomClient = CONCAT( UPPER( LEFT(NEW.PrenomClient,1) ) , LOWER( SUBSTR( NEW.PrenomClient,2 ) ) );

Example 4: Create Trigger in phpMyAdmin

DELIMITER //

CREATE TRIGGER contacts_after_insert
AFTER INSERT
   ON contacts FOR EACH ROW

BEGIN

   DECLARE vUser varchar(50);

   -- Find username of person performing the INSERT into table
   SELECT USER() INTO vUser;

   -- Insert record into audit table
   INSERT INTO contacts_audit
   ( contact_id,
     created_date,
     created_by)
   VALUES
   ( NEW.contact_id,
     SYSDATE(),
     vUser );

END; //

DELIMITER ;

Example 5: how to make trigger in phpmyadmin

ALTER TABLE sales_details
ADD FOREIGN KEY fk_product_code(product_code)
REFERENCES products(product_code)
ON DELETE CASCADE;

Example 6: how to make trigger in phpmyadmin

delimiter // 
 CREATE TRIGGER removeforeing 
  BEFORE DELETE ON products
  FOR EACH ROW BEGIN
    DELETE FROM sales_details WHERE product_code = OLD.product_code;
 END// 
 delimiter ;

Tags:

Sql Example