Triggers in MySQL
Trigger MySQL: Trigger can be used in two ways with before and after with Delete ,insert and update command .Let me show you a example of before update . I have created two table employee and employee_audit . employee table is table where my raw data will be stored and employee_audit table is table where to store data after changes or can say trigger execution . Table structure of employee and employee_audit table : CREATE TABLE `test`.`employee` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(20) DEFAULT NULL, `lstname` varchar(10) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=latin1; CREATE TABLE `test`.`employee_audit` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(20) DEFAULT NULL, `lstname` varchar(20) DEFAULT NULL, `action` varchar(50) DEFAULT NULL, `upd_datetime` datetime DEFAULT NULL, `newname` varchar(20) DEFAULT NULL, ...