Mysql trigger and stored procedure Test 1. to test the trigger and stored procedure, first CREATE a simple TABLE: www.2cto.com create table 'airuser' ('userid' int (11) not null AUTO_INCREMENT, 'username' varchar (128) not null, primary key ('userid') ENGINE = InnoDB default charset = utf8 2. CREATE a record TABLE: create table 'airuser _ record '('id' int (11) not null AUTO_INCREMENT, 'username' varchar (45) default null, 'edittime' timestamp null default null, 'edittype' varchar (45) default null, primary key ('id') ENGINE = InnoDB default charset = utf8 3. write a TRIGGER for the INSERT operation: drop trigger insert_trigger; delimiter | create trigger insert_trigger before insert on airuserFOR each row begininsert into airuser_record SET username = NEW. username, edittime = now (), edittype = 'insert'; END; | show triggers; 4. stored procedure for batch insert: DROP procedure createUsers; delimiter | create procedure createUsers (IN count int) begindeclare I int; set I = 0; while I <count doinsert into airuser set username = concat ('user _ ', I); set I = I + 1; end while; end; | show procedure status; 5. call the stored procedure to verify that the stored procedure is working and that the trigger can be correctly triggered before the record is inserted: call createUsers (10); 6. finally, the record table is inserted for verification again: SELECT * FROM mars_jpa.airuser_record;