From Jacques.Kilchoer@quest.com Tue, 08 May 2001 20:31:12 -0700 From: Jacques Kilchoer Date: Tue, 08 May 2001 20:31:12 -0700 Subject: RE: Table autonumber field Message-ID: MIME-Version: 1.0 Content-Type: text/plain Title: RE: Table autonumber field > -----Original Message----- > From: Mike T [mailto:mtmind@the-beach.net] > > I need to create an autonumber field in an Oracle Table (from > a SQL server table identity field) , I was looking for a > default value that I could assign (select max(ID) + 1)  or > some way to create an identity field > or use a trigger after insert but nothing seems to work for > me. Any help would be appreciated, This field also has to be > the primary Key . Read the Oracle SQL manual about the use of sequences and triggers. Here's an example: SQL> create sequence s ; Sequence created. SQL> create table t (id number primary key, name varchar2 (30)) ; Table created. SQL> create trigger b4it   2  before insert on t   3  for each row   4  begin   5     select s.nextval into :new.id from dual ;   6  end ;   7  / Trigger created. SQL> insert into t (name) values ('Mao Chu') ; 1 row created. SQL> insert into t (name) values ('Mohandas Gandhi') ; 1 row created. SQL> commit ; Commit complete. SQL> select * from t ;         ID NAME ---------- ------------------------------          1 Mao Chu          2 Mohandas Gandhi ------ Jacques R. Kilchoer (949) 754-8816 Quest Software, Inc. 8001 Irvine Center Drive Irvine, California 92618 U.S.A. http://www.quest.com