Trigger question (auto-increment)

Bart Pietercil bart.pietercil at gmail.com
Thu Oct 18 08:59:52 CDT 2007


On 18-okt-07, at 15:51, Martin S. wrote:

> Bart Pietercil schrieb:
>> Hi Martin,
>>
>> On 18-okt-07, at 14:20, Martin S. wrote:
>>
>>> 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
>>
>>
>>
>> New.AutoID = SELECT MAX(AutoID)+1 FROM Table1
>>
> no, this does not work inside a trigger (unexpected token: SELECT)
> :(
>
What if you write this like a function call that returns an autoID.
then you get

New.AutoID = CALL myFunction()

We are using CALLs from within triggers so CALL should work

hth

Bart





More information about the Valentina mailing list