Thread: Create table

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2002
    Location
    Utah
    Posts
    20
    Rep Power
    0

    Create table


    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?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    68
    Rep Power
    11
    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, ......);

    Good Luck,
    Dan
  4. #3
  5. No Profile Picture
    Senior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    Canada
    Posts
    305
    Rep Power
    11
    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
    nomaxvalue
    nocycle
    nocache
    ;

    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.

    Regards
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2002
    Location
    Utah
    Posts
    20
    Rep Power
    0
    Thanks for the help. Looks like I got some homework to do on sequences & triggers.;-)

IMN logo majestic logo threadwatch logo seochat tools logo