?
Solved

Oracle Sequence

Posted on 2014-07-31
9
Medium Priority
?
330 Views
Last Modified: 2014-08-05
I have a table that Im working with and it has a sequence to get the next value for the ID field on the table. The ID field is NOT a primary key. I want to change it but for now I see it has dependencies and I dont want to mess anything up. I noticed that when I did an Insert it is inserting a duplicate value of 3 into the this field. I opened the Sequence and the Last Number is now 3 so I understand how this happened. My question is, can I have the LastNumber look at my ID field and determine the next number? Or does this have to be a primary key in order for that to happen?

Thanks for any help!!
0
Comment
Question by:jknj72
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 23

Expert Comment

by:Jens Fiederer
ID: 40231906
Assuming you are using actual sequences,  they have nothing to do with primary keys (except that they are frequently used for setting their values).

The same sequence could be used for multiple tables, and sequences can be reset by dropping and recreating.

This site describes how the value stored in a sequence can be changed:

http://www.gokhanatil.com/2011/01/how-to-set-current-value-of-a-sequence-without-droppingrecreating.html
0
 

Accepted Solution

by:
jknj72 earned 0 total points
ID: 40231921
I managed to go around it for now. And what do you mean by "Assuming you are using actual sequences"?
0
 
LVL 23

Expert Comment

by:Jens Fiederer
ID: 40231935
I meant the actual objects called SEQUENCE and created by

CREATE SEQUENCE sequence_name;

statements (rather than just a logical sequence of numbers).
0
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 

Author Comment

by:jknj72
ID: 40231966
well to answer your question I am using Actual Sequences
0
 
LVL 35

Expert Comment

by:johnsone
ID: 40231981
Also, be aware that a sequence can get to its maximum value and then start again at the minimum value.  This is controlled by specifying CYCLE or NOCYCLE when creating the sequence.
0
 
LVL 35

Expert Comment

by:johnsone
ID: 40231984
FYI,

MAX + 1 will not work if multiple users insert records at the same time.  You will most likely see duplicate values.
0
 
LVL 23

Expert Comment

by:Jens Fiederer
ID: 40231990
As johnsone said, that is a big no-no.
0
 
LVL 29

Expert Comment

by:MikeOM_DBA
ID: 40232804
You are making a mistake, listen to johnsone or .... SUFFER THE CONSEQUENCES.
0
 

Author Closing Comment

by:jknj72
ID: 40240748
FYI, I simply did a MAX + 1 on the ID field and used that for my next value. I know, not the ideal way to do things but until I can decipher whether changing the table and putting a primary key on it, possibly with a trigger for incrementing, then this will have to do...
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

A company’s centralized system that manages user data, security, and distributed resources is often a focus of criminal attention. Active Directory (AD) is no exception. In truth, it’s even more likely to be targeted due to the number of companies …
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
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
Suggested Courses

801 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