User Defined variables and Triggers

Bart Pietercil bart.pietercil at gmail.com
Fri Jun 1 09:24:02 CDT 2007


Hi List, Ruslan

Is there a way to use User Defined Variables (ie. @MyName) inside  
triggers.

The idea is to first pass the userid to the database with SET @userid  
= anID

and then inside a trigger use the variable @userid to store the ID in  
the fields created_by and updated_by

like this:

     CREATE OR REPLACE TRIGGER trig_ratingsystems_BI BEFORE INSERT ON  
rating_systems FOR EACH ROW " + _
     "BEGIN " + _
     "NEW.created_datetime = NOW();" + _
     "NEW.created_by = @userid ;" + _
     "NEW.updated_datetime = Now();" + _
     "NEW.updated_by = @userid;" + _
     "END;" + EndOfLine + _
     "CREATE OR REPLACE TRIGGER trig_ratingsystems_BU BEFORE UPDATE  
ON rating_systems FOR EACH ROW " + _
     "BEGIN "+ _
     "NEW.updated_datetime = Now();" + _
     "NEW.updated_by = @userid;" + _
     "END;"

I can see a problem that the @userid would not be set (but that's up  
to the programmer of course) before the trigger is triggered

Thanks for looking into this

Bart



More information about the Valentina mailing list