Rhino wrote:
"narayana" <va***********@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
hi gurus,
here is the problem
i have a table with 2 columns first one is the primary key
with small int next one is integer
then i need a trigger with out using sequence or identity that when i
insert a second column the first column should be fired with and number
next onward it should be incremented
I just read your question twice and I don't understand what you are trying
to do. Can you clarify the question?
Also, what operating system are you using and what version of DB2 are you
running?
Rhino
Taking some guesses....
CREATE TABLE T(c1 NOT NULL SMALLINT PRIMARY KEY, c2 INTEGER);
CREATE TRIGGER trg1 NO CASCADE BEFORE INSERT ON T
REFERENCING NEW AS n FOR EACH ROW MODE DB2SQL
WHEN (n.pk IS NULL)
SET n.pk = (SELECT COALESCE(MAX(pk), 0) + 1 FROM T);
Should work as long as only single rows are inserted.
For multirow need to use the counter function in sqllib/samples/c
Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab