| Author |
Message |
mob1012 *nix forums beginner
Joined: 18 Jul 2006
Posts: 2
|
Posted: Tue Jul 18, 2006 2:56 pm Post subject:
Re: unique generated numbers
|
|
|
Thank you - I'll try it
Serge Rielau wrote:
| Quote: | create trigger comp_id_num
BEFORE update on component_master
REFERENCING NEW AS N for each row
SET component_id = Generate_unique()
|
|
|
| Back to top |
|
 |
Serge Rielau *nix forums Guru
Joined: 29 Apr 2005
Posts: 1583
|
Posted: Tue Jul 18, 2006 2:49 pm Post subject:
Re: unique generated numbers
|
|
|
create trigger comp_id_num
BEFORE update on component_master
REFERENCING NEW AS N for each row
SET component_id = Generate_unique()
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
IOD Conference
http://www.ibm.com/software/data/ondemandbusiness/conf2006/ |
|
| Back to top |
|
 |
mob1012 *nix forums beginner
Joined: 18 Jul 2006
Posts: 2
|
Posted: Tue Jul 18, 2006 1:58 pm Post subject:
unique generated numbers
|
|
|
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. |
|
| Back to top |
|
 |
Google
|
|
| Back to top |
|
 |
|