Hi all,
I am new to DB2 for windows and I have a question about generating unique
numbers for a primary key. I have decided to use the generate_unique()
statement in a trigger to create this number. I have written the trigger like
this:
create trigger comp_id_num
after update on component_master
for each row
insert into component_master (component_id) values (Generate_unique())
where component_master is the table name, component_id is the column and
primary key
I cannot use this because the trigger is not used until after update and the
primary key cannot be null before update. I don't know what to do. I thought
about stored procedures or functions, but I'm really not familiar with either.
Any help will be appreciated. Thank you.
Serge Rielau - 18 Jul 2006 15:49 GMT
create trigger comp_id_num
BEFORE update on component_master
REFERENCING NEW AS N for each row
SET component_id = Generate_unique()

Signature
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
IOD Conference
http://www.ibm.com/software/data/ondemandbusiness/conf2006/
mob1012 - 18 Jul 2006 15:56 GMT
Thank you - I'll try it
>create trigger comp_id_num
> BEFORE update on component_master
> REFERENCING NEW AS N for each row
> SET component_id = Generate_unique()