Trigger in MySQL

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);

Leave a Reply

You must be logged in to post a comment.


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.