I've been occupied with lot of work and could not find the time to sit and write some posts...
But this was sooo interesting and couldn't keep from coming here and posting it for ur knowledge...
This is the first trigger I have written.. It's something that is used to update a tables called values_table and template_table. I have changed some of the names of the table since it's from my cmpny project ;)
DELIMITER |
CREATE TRIGGER xxtriggername AFTER INSERT ON channel
FOR EACH
ROW BEGIN
INSERT INTO values_table
VALUES
(NULL , NEW.channel_id, 1, 1, 0.0),
(NULL , NEW.channel_id, 1, 2, 0.0),
(NULL , NEW.channel_id, 1, 3, 0.0),
(NULL , NEW.channel_id, 1, 4, 0.0),
(NULL , NEW.channel_id, 1, 5, 0.0),
(NULL , NEW.channel_id, 1, 6, 0.0),
(NULL , NEW.channel_id, 1, 7, 0.0),
(NULL , NEW.channel_id, 1, 8, 0.0),
(NULL , NEW.channel_id, 1, 9, 0.0),
(NULL , NEW.channel_id, 1, 10, 0.0),
(NULL , NEW.channel_id, 1, 11, 0.0),
(NULL , NEW.channel_id, 1, 12, 0.0),
(NULL , NEW.channel_id, 1, 13, 0.0),
(NULL , NEW.channel_id, 1, 14, 0.0),
(NULL , NEW.channel_id, 1, 15, 0.0),
(NULL , NEW.channel_id, 1, 16, 0.0),
(NULL , NEW.channel_id, 1, 17, 0.0),
(NULL , NEW.channel_id, 1, 18, 0.0),
(NULL , NEW.channel_id, 1, 19, 0.0),
(NULL , NEW.channel_id, 1, 20, 0.0),
(NULL , NEW.channel_id, 1, 21, 0.0),
(NULL , NEW.channel_id, 1, 22, 0.0),
(NULL , NEW.channel_id, 1, 23, 0.0),
(NULL , NEW.channel_id, 1, 24, 0.0);
INSERT INTO template_table VALUES (1,'Default template',NEW.channel_id);
END;
|
DELIMITER ;
Btw these links should help you get started if you are also new to triggers...
http://dev.mysql.com/doc/refman/5.0/en/create-trigger.html
http://www.digitalpropulsion.org/Programming/Triggers_in_MySQL_5_0
3 comments:
This comment has been removed by the author.
have you tried this tool called sqlyog? its easy to create triggers with that..i did few without even know much about it..think you should check it out.
Yeah machan... actually we are using that... btw I created first trigger using command line :)
Post a Comment