December 10th, 2003, 06:53 PM
My first time in oracle. Im trying to create tables. Im using dbvisualizer. (i love that) What I cant get is how to auto increment my primary key fields.
This project was originaly in MySQL, easy enough to auto_increment there. How do I do it in dbvisualzer?
December 11th, 2003, 09:42 AM
The best way to do it in Oracle is via a sequence:
create sequence table_pk_seq;
and then in the insert statement:
insert into <table> values (table_pk_seq.nextval, ......);
December 11th, 2003, 10:12 AM
I dont have any idea about dbvisualizer, however, Oracle allows you to generate auto number series by creating SEQUENCE, these auto generated numbers can be used in your table at the time of inserting rows. Oracle gives you two pseudo column NEXTVAL and CURRVAL to get next vale and current value of the sequence repectively. I give you an idea, how can you do this:
First create the sequence:
SQL>CREATE SEQUENCE emp_seq
start with 1
increament by 1
Now you can use this auto generated value in the emp table as follows:
insert into emp (empno, ename, sal, deptno)
values (seq_emp.nextval, 'Oracle Guru', 2300, 10)
How can you do this by dbvisualizer?, it's you home work.
December 11th, 2003, 05:21 PM
Thanks for the help. Looks like I got some homework to do on sequences & triggers.;-)