473,394 Members | 1,750 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Sequence problem

4
I'm trying to learn about SEQUENCE and I came accross this example:

INSERT INTO student (studentID, name, address)
values (sID.NextVal, 'Albert', '123, Sage Ave., NY. 12180');

the column name used for the SEQUENCE's NEXTVAL in this example is studentID. Where is studentID defined or should it be defined?

As you can see studentID is not used in the CREATE statement below so where is it coming from?

CREATE SEQUENCE sID
INCREMENT BY 1
START WITH 100
ORDER;

Thanks for your assistance! Andy
Sep 13 '07 #1
4 2224
debasisdas
8,127 Expert 4TB
I'm trying to learn about SEQUENCE and I came accross this example:

INSERT INTO student (studentID, name, address)
values (sID.NextVal, 'Albert', '123, Sage Ave., NY. 12180');

the column name used for the SEQUENCE's NEXTVAL in this example is studentID. Where is studentID defined or should it be defined?

As you can see studentID is not used in the CREATE statement below so where is it coming from?

CREATE SEQUENCE sID
INCREMENT BY 1
START WITH 100
ORDER;

Thanks for your assistance! Andy
Hi Andy

studentID is the name of the column in the table student.
that is not part of the sequence.

from the sequence it is trying to insert value to the column using sequencename.nextval
Sep 14 '07 #2
amitpatel66
2,367 Expert 2GB
I'm trying to learn about SEQUENCE and I came accross this example:

INSERT INTO student (studentID, name, address)
values (sID.NextVal, 'Albert', '123, Sage Ave., NY. 12180');

the column name used for the SEQUENCE's NEXTVAL in this example is studentID. Where is studentID defined or should it be defined?

As you can see studentID is not used in the CREATE statement below so where is it coming from?

CREATE SEQUENCE sID
INCREMENT BY 1
START WITH 100
ORDER;

Thanks for your assistance! Andy
Andy,

SEQUENCE will make sure that every time a new record is inserted in table STUDENTS, the STUDENTID value will be the next value of the sequence.

SEQUENCES are used to manage the values of PRIMARY KEY column where in DUPLICATES are not allowed.
Sep 14 '07 #3
areya
4
Andy,

SEQUENCE will make sure that every time a new record is inserted in table STUDENTS, the STUDENTID value will be the next value of the sequence.

SEQUENCES are used to manage the values of PRIMARY KEY column where in DUPLICATES are not allowed.
*******************************
You mentioned that SEQUENCES are used to manage the values of PRIMARY KEY column. Can you elaborate? If I create a new column for the NEXTVAL to be inserted into, because I'm trying to allow duplicates, do I make that column part of the PRIMARY KEY to insure that duplicates are inserted. Appreciate your help! Andy
Sep 14 '07 #4
amitpatel66
2,367 Expert 2GB
*******************************
You mentioned that SEQUENCES are used to manage the values of PRIMARY KEY column. Can you elaborate? If I create a new column for the NEXTVAL to be inserted into, because I'm trying to allow duplicates, do I make that column part of the PRIMARY KEY to insure that duplicates are inserted. Appreciate your help! Andy
Andy,

If you make a column PRIMARY KEY, then you cannot insert duplicate values to that column.

For Eg: I have a table EMP that cotains:
Empno, Ename,Address,Hiredate,Salary.

I make Empno as PRIMARY KEY. So now no two employees will have same EMPNO.

And I will make use of sequence to AUTOGENERATE the value of Empno for every new employee details inserted in to EMP table.

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO emp VALUES(sid.NEXTVAL,'AAAA','20 ABC Road',SYSDATE,10000);
  2.  
So in the above INSERT statement, the EMPNO will be autogenerated starting from 1,2,3 and so on.
Sep 14 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Dan | last post by:
Hello there. I have recently been tasked with creating a mySql database. I am much more used to using Oracle, so I guess my problem is translating Oracle into mySql. My current problem is the...
2
by: Krzysztof Opała | last post by:
Hi I've got my CORBA application written in Borland C++ Builder, using Visibroker. What I wanna do is get from server a set of strings (the number of string is not constant). I was trying to do it...
10
by: Anthony Best | last post by:
I'm working on an idea that uses sequences. I'm going to create a table like this: id serial, sequence int, keyword varchar(32), text text for every keyword there will be a uniq sequence...
4
by: Eric E | last post by:
Hi, I have a question about sequences. I need a field to have values with no holes in the sequence. However, the values do not need to be in order. My users will draw a number or numbers from...
1
by: Marek Lewczuk | last post by:
Hello, I would like to ask if my problem with sequence is a proper behavior or this is a bug (probably not)... I have a table: CREATE TABLE "testtable" ( "serialfield" SERIAL,...
3
by: kevin | last post by:
Is that even possible? I am creating a web service in .NET to expose some already created .NET programs to other groups. One group is writing the client in PERL, and thus wishes the wsdl schema...
8
by: regis | last post by:
Greetings, about scanf matching nonempty sequences using the "%" matches a nonempty sequence of anything except '-' "%" matches a nonempty sequence of anything except ']" matches a nonempty...
14
by: pat270881 | last post by:
hello, I have to implement a sequence class, however the header file is predefined class sequence { public: // TYPEDEFS and MEMBER CONSTANTS
5
by: Anan18 | last post by:
Hello sir, I'm supposed to Implement and Test the sequence Class Using a Fixed-Sized Array (Chapter 3), from Data Structures & Other objects using c++. The header file is provided, and so is a test...
8
by: Slaunger | last post by:
Hi all, I am a Python novice, and I have run into a problem in a project I am working on, which boils down to identifying the patterns in a sequence of integers, for example ..... 1 6 6 1 6 6...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.