Create Mysql Trigger

  • Connect to mysql server
    • mysql --password=******
  •  Select Database
    • use [database name] 
  • Create Trigger
    • DELIMITER //
      CREATE TRIGGER add_mediatrix_ports after insert on mediatrix_boxes
      FOR EACH ROW BEGIN
      declare l_loop int default 1;
      while l_loop
      insert into mediatrix_ports (mediatrix_boxid, port, operational, date_created, created_userid, date_modified, modified_userid) VALUES (new.id, l_loop, 1, "2009-07-07", 1, "2009-07-07 16:20:23", 1);
      set l_loop := l_loop + 1;
      end while//
    • DELIMITER //
      create trigger insert_tut_line after insert on tut_slots for each row
      begin
      declare l_loop int default 1;
      while l_loop < 9 do
      INSERT INTO `tut_lines` (tut_slotid, line, date_created, created_userid, date_modified, modified_userid, operational) VALUES (new.id, l_loop, '2007-05-24', 1, '2009-07-07 13:39:32', 1, 1);
      set l_loop := l_loop + 1;
      end while;
      end;

0 comments:

Post a Comment