Trigger question (auto-increment)

Martin S. blackfin at elfenherz.de
Thu Oct 18 07:20:31 CDT 2007


As I understand, I can emulate auto-increment fields with triggers.
But how?
Is it possible to get the maximum value of a field inside a trigger?
What I like to do is, on INSERT, find the maximum value of field 
"autoid", increment it by one and set the new autoid to this.

I want a trigger that does something like this (pseudo code):

CREATE OR REPLACE TRIGGER TABLE1_BEFORE_INSERT BEFORE INSERT
ON TABLE1 FOR EACH ROW
BEGIN
    maxquery = "SELECT MAX(AutoID) FROM TABLE1" ;
    newID =   maxquery['AutoID'] + 1;
    NEW.AutoID = newID ; 
END


greetings,

Martin


More information about the Valentina mailing list