Subject Best way to check a value
Author Paco Ruiz
Hi

I have a table MY_TABLE with a integer field NUM.
NUM must be unique, so i create a index.
When i insert a record in the table, i must check if NUM exists.
If NUM exists, i calculate Max(NUM)+1, and this will be the new value.
(all this is very tipic)

What is the best/quick way to do this?

At the moment, have this code in a Before Insert Trigger
...
DECLARE VARIABLE N INTEGER;
BEGIN
SELECT NUM
FROM MY_TABLE
WHERE ( NUM = NEW.NUM )
INTO :N;

IF ( N IS NOT NULL ) THEN
BEGIN
SELECT MAX(NUM)
FROM MY_TABLE
INTO N;
NEW.NUM = N+1;
END
END


Is it better perhaps to make this checking in the client (Delphi)
program? Why?

Saludos
Paco