0

I want to create table with auto_increment . I am using oracle11g database

create table employee(id number(6) auto_increment,first_name varchar2(20) default null,last_name varchar2(20) default null,salary number(7) default null);

this is the query that I am executing but the table is not created . I have tried sequence also .

for sequence I did

create table employee(id number(6) name_of_sequence.nextval,first_name varchar2(20) default null,last_name varchar2(20) default null,salary number(7) default null);

then also my table is not created . thank you

Rashad
  • 11,057
  • 4
  • 45
  • 73
Sam
  • 7
  • 4
  • 1
    There is no auto increment feature in Oracle 11g. You have write your own logic. The feature you are looking has been [introduced in Oracle 12c](http://www.oracle-base.com/articles/12c/identity-columns-in-oracle-12cr1.php). – San Aug 26 '14 at 04:40
  • possible duplicate of [Add a auto increment primary key to existing table in oracle](http://stackoverflow.com/questions/11464396/add-a-auto-increment-primary-key-to-existing-table-in-oracle) – Noel Aug 26 '14 at 05:59

3 Answers3

0

You may create an object known as a sequence in oracle e.g.

CREATE SEQUENCE my_seq;

Then reference this in your code with my_seq.nextval in a stored procedure, trigger or in your client code. The sequence is not bound to the column live in sqlserver. As mentioned this may be possible in later versions of oracle.

kayakpim
  • 985
  • 2
  • 8
  • 28
0

The usual practice that I use and works well for me is that you create the column with usual data-type of integer/number. perform as follows

create table MyTab
(
My_auto_inc integer/number,....
);

and when insert you this do

Insert Into MyTab(My_auto_inc,...)
Values(Seq_MyTab.nextval,...);

I normally use the table name after the Seq as a good coding practice naming convention easy to remember

Ajwad
  • 53
  • 1
  • 7
0

Auto_increment is not available in version 11g. You need to look up Sequences and Triggers to do this.

kurdtpage
  • 3,142
  • 1
  • 24
  • 24