trigger after insert

Bart Pietercil bart.pietercil at gmail.com
Tue Sep 25 10:32:17 CDT 2007


On 25-sep-07, at 17:21, Ivan Smahin wrote:

> Hello Bart,
>
> Tuesday, September 25, 2007, 6:07:25 PM, you wrote:
>
>> Hi List,
>
>> can somebody explain why this trigger
>
>> CREATE OR REPLACE TRIGGER "trigger_tbl_users_AI" AFTER INSERT
>
>>      ON "tbl_users" FOR EACH ROW
>
>>      BEGIN
>>         if @user_id IS null then
>>                 NEW.objptr_created_by = New.recid;
>
>>                 NEW.objptr_modified_by = New.recid;
>>         End IF
>>      END;
>
>> generates this error when executed in the sql editor:
>
>> Error: Kernel error: 0x91504. Trigger "trigger_tbl_users_AI": time
>> "AFTER" is not supported in this context.
>
> Sorry, I was wrong:
> It  must  be  "BEFORE  INSERT"  trigger  to  get  ability  to operate
> with NEW.field.

confused now

do you mean I CAN use New.recid in the context of a BEFORE INSERT  
trigger ?

I CAN create a record and in the before insert trigger refer to the  
recid that is not yet created (maybe it is created but not yet  
inserted) ?
That would be the ideal solution so my first example would be correct:

CREATE OR REPLACE TRIGGER "trigger_tbl_users_BI" BEFORE INSERT

     ON "tbl_users" FOR EACH ROW

     BEGIN
	if @user_id IS NOT null then
		NEW.objptr_created_by = @user_id;

		NEW.objptr_modified_by = @user_id;
	else
		NEW.objptr_created_by = NEW.recid;-----> ??
		NEW.objptr_modified_by = NEW.recid;---->??
	End IF
         NEW.creation_dt = NOW();

         NEW.modification_dt = NOW();

		

     END;


TIA

Bart


More information about the Valentina mailing list