Saturday, April 20, 2013

Sequences in Oracle SQL



What is Sequence?

We create a sequence to generate a unique numbers.

How to Create sequences

We create a sequence by using CREATE SEQUENCE statement

For example:

Create sequence for the EMPNO column of the EMP table begins the sequence at 1 and maximum value at 1000.

CREATE SEQUENCE NEWEMP_EMPNO
INCREMENT BY 1
START WITH 1
MAXVALUE 1000;

=>Explanation of Above Query:

The INCREMENT BY option specifies the gap between sequence numbers
START WITH option specifies the first number in the sequence.
MAXVALUE option specifies the maximum value the sequence can generate.

=>Other option not included in example

NOMAXVALUE: a default maximum value
NOMAINVALUE: specific the minimum sequence value.
CYCLE: cycle option specifies that the sequence continues to generate values.
CACHE: specifies the number of values the server reallocates in memory

Feel Free to Comment:              Shabbir Ahmad (SE)


No comments:

Post a Comment

Thank You For Comment