views:

88

answers:

4

i am trying to code for my system in NetBeans IDE 6.5 to auto generate ID numbers for me like autonumbers in Ms Access. does any one have any ideas about going about that?i mean code for it.

A: 

What database system are you using? If it's something SQL based:

CREATE TABLE $tblname (id int(10) NOT NULL auto_increment PRIMARY KEY (id))

Try using auto_increment , such as in the example above.

Alya
A: 

If you're using JavaDB you need the GENERATED AS IDENTITY option on a field in your CREATE TABLE statement.

Dave Webb
A: 

In the Windows API you can create a Guid. I'm sure there is some similar UID API for Netbeans.

kenny
A: 

If you're using Oracle, you will need a sequence for each table.

once you have the sequence you can create a trigger like this:

Create or Replace trigger incrementOnInsert
before insert on TABLE
for each row
begin
    select sequence.nextval into :new.id from dual;
end;
Jonathan