Solved

Auto Increment an ID in Oracle 10G via GUI

Posted on 2009-07-01
3
1,800 Views
Last Modified: 2012-05-07
I'm a SQL guy; in MS SQL, I can set a Primary Key with an auto increment with whatever seed values that are needed.  Can I do this in the Oracle GUI or do I need to to do this via SQL Plus?

Thx
0
Comment
Question by:Glen_D
3 Comments
 
LVL 35

Expert Comment

by:johnsone
ID: 24754188
Oracle does not have an auto increment field.

You would have to create a sequence to keep track of the values.  Then you can either put the increment of the sequence into the insert statement, or you can use a trigger to generate it.
0
 
LVL 40

Expert Comment

by:mrjoltcola
ID: 24754225
By GUI do you mean Enterprise manager? If so, yes, but you use sequences.

There is no auto-increment column type, however, you must use the sequence in your insert statemnts for that column. You can implement auto-increment columns using a before insert trigger.
0
 
LVL 48

Accepted Solution

by:
schwertner earned 500 total points
ID: 24754486
In Oracle you can create sequence and use it in BEFORE INSERT trigger to provide a primary key value


create table test (id number, testdata varchar2(255));


create sequence test_seq
start with 1
increment by 1
nomaxvalue;

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

0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question