March 28, 2008

Bikin AutoIncrement di ORACLE~

wah udah lama ga posting , lg sibuk neeehhh ….. heheh. tp untuk postingan kali ini saya mo nulis caranya gimana bikin autoincrement di oracle , maklum kemaren nyari2 caranya baru ketemu barusan..

pertama kita buat table dulu misalnya namanya my_test

create table my_test (
id number,
data varchar2(255)
);

abis gitu buat sequencenya

create sequence test_seq
start with 1
increment by 1
nomaxvalue;

dan sentuhan terakhir bikin trigger dech

create trigger test_trigger
before insert on my_test
for each row
begin
select test_seq.nextval into :new.id from dual;
end;

nah klo udah gitu dan ga ada error , coba test dengan mnginsert data ke file “data” pada tabel my_test tersebut

insert into my_test(data) values( ‘hume’);

insert sebanyak 10 kali , biar keliatan hasilnya, hehehehehhe …..

dan pake perintah “select * from my_test” buat ngeliat data yg udah ke simpan .

sekian ….

Comments »

The URI to TrackBack this entry is: http://simplemy.blogsome.com/2008/03/28/bikin-autoincrement-di-oracle/trackback/

No comments yet.

RSS feed for comments on this post.

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>



Anti-spam measure: please retype the above text into the box provided.