use websitelogdb; #建立表 CREATE TABLE `test` ( `idtest` int(11) NOT NULL AUTO_INCREMENT, `testcol` varchar(45) DEFAULT NULL, `testcol1` varchar(45) DEFAULT NULL, PRIMARY KEY (`idtest`) ) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8; SELECT * FROM websitelogdb.test; set @id = 'mysql'; #建立Trigger DROP TRIGGER IF EXISTS t_afterinsert_on_test; delimiter | CREATE TRIGGER t_afterinsert_on_test AFTER INSERT ON websitelogdb.test FOR EACH ROW BEGIN set @id = new.idtest; END; | delimiter ; #調用Trigger觸發器 insert into websitelogdb.test(testcol, testcol1) values('1','1'); select @id;