Trigger in MySQL
Trigger in MySQL
A trigger is an SQL command (or block of commands) that is fired when a particular operation such as an UPDATE or DELETE occurs on the table to which the trigger belongs. The trigger can access the original as well as the new data for the row in question. A DROP DATABASE on a database with triggers fails, so you must drop triggers before droping database.
Syntax:
CREATE TRIGGER trigger_name trigger_time trigger_event ON tbl_name FOR EACH ROW trigger_stmt
Example:
CREATE TABLE urls(id INT(11), url varchar(255),urlhash varchar(32));
CREATE TRIGGER cal_hash BEFORE INSERT ON urls FOR EACH ROW SET NEW.urlhash = md5(NEW.ulr);
