Connecting Tech Pros Worldwide Help | Site Map

MySql 5.0 - Trigger with Bussiness Logic

Member
 
Join Date: Jul 2007
Posts: 37
#1: Nov 24 '08
Hai,

I would like to know if i can include bussiness logic in Trigger.

For Example:

On a insert/update on a table(primary) i want to insert values to other table(secondary).

A insert is done on a primary table only when their are no records present w.r.t the id .If the id is present in the table an update action is performed.
I will have to check if the id is present or not.But not getting to know how to implement it in trigger.

Thank You,
Sindhu
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,739
#2: Nov 26 '08

re: MySql 5.0 - Trigger with Bussiness Logic


Hi.

Triggers can not use dynamic SQL statements. You would have to use a procedure or a function to do this.

Note that you can not call procedures or functions that use dynamic SQL statements from a trigger either.

I would recommend simply adding a "AddUser" or "AddClient" procedure to your database that you would call rather than adding data using the INSERT statement.
That way you can add whatever logic you want before you insert anything.
Reply