Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Database Servers
DB2InformixIngresMS SQLOraclePervasive.SQLPostgreSQLProgressSybase
Desktop Databases
FileMakerFoxProMS AccessParadox
General
General DB TopicsDatabase Theory
Related Topics
Java Development.NET DevelopmentVB DevelopmentMore Topics ...

Database Forum / DB2 Topics / July 2006

Tip: Looking for answers? Try searching our database.

unique generated numbers

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
mob1012 - 18 Jul 2006 14:58 GMT
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()
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.