Oracle - Create an autonumber field
67Before anything, i want to say that this article was posted on my personal blog, and i only put it here because the chances that this article possible be useful for anyone are greater with HubPages.
Now, take a look:
If you want to create an autoincrements field in a table, using Oracle, you may do this by using sequences.
What are sequences?
Well, sequence is a command that gives to you the power to do this.
Nothing better than an example:
create table user
( id number(10),
name varchar2(32),
primary key(id)
);
If you want the id field increase automatically, you use the sequence:
create sequence user_seq
start with 1
increment by 1
nomaxvalue;
Naturally, as you can see, when new records are entry on table, the id field will be increasing.
insert into user values(user_seq.nextval, 'andre');
select * from user
... Experiment yourself now :)
Just for curiosity, the sintaxe of sequence is:
CREATE SEQUENCE sequence_name
MINVALUE value
MAXVALUE value
START WITH value
INCREMENT BY value
CACHE value;
This post is on my personal blog too, in portuguese languange, here.
|
|
Oracle Database 10g RMAN Backup & Recovery by Matthe...
Current Bid: $57.11
|
|
|
Oracle Essentials by Jonathan Stern Oracle Database 10g
Current Bid: $4.99
|
|
|
NEW Oca Oracle Database 11g: SQL Fundamentals I Exam...
Current Bid: $35.90
|
|
|
NEW OCA/OCP Oracle Database 11g All-in-One Exam Guid...
Current Bid: $55.99
|
|
|
Database Systems Using Oracle (2nd IE)
Current Bid: $59.99
|
|
|
Pro Oracle Database 10g Rac on Linux by Julian Dyke,...
Current Bid: $41.99
|
PrintShare it! — Rate it: up down flag this hub









surender sara says:
11 months ago
I would suggest to take a look at free Oracle DBA and APPS DBA Training at
http://www.orabyte.com/eLearning2/index.php?target
There are 100's of free vidoes and 1000+ scripts in the DBA and APPS dba tool at
http://www.orabyte.com/eLearning2/index.php?target
I use this tool and is awesome. Makes my life easy. Once you become DBA and APPS DBA you will need to get organized.