Friday, April 14, 2017

How to Define an Auto Increment Primary Key in Oracle



 Create the table

 create table honnikery (
      id number primary key,
      name varchar2(100)
    );

Create sequence
 create sequence honni_id_seq;

create a trigger that uses the sequence to populate the primary key
create trigger trg_honni_id
      before insert on honnikery
      for each row
    begin
      select honni_id_seq.nextval
        into :new.id
        from dual;
    end;



insert into honnikery( name ) values ('honnikery Prabhakar');
insert into honnikery( name ) values ('Biswa');

No comments:

Post a Comment