SQL Sequences

SQL Sequences

Sequences are frequently used in databases because many applications require each row in a table to contain a unique value and sequences provide an easy way to generate them

How to find sequences in SQL:

Syntax: desc user_sequences;

How to create the sequence:

Syntax:

CREATE SEQUENCE  schema_name

[INCREMENT BY interval]

[START WITH the first number]

[MAXVALUE max value | NOMAXVALUE]

[MINVALUE min value | NOMINVALUE]

[CYCLE | NOCYCLE]

[CACHE cache size | NOCACHE]

[ORDER | NOORDER];

 

Ex:

Create Table

 

Now, Create a sequence

 

 

Sequence created with conditions needs to be performed.

 

To See sequence’s current value:

Syntax: select seq_name.currvalue from dual;

Ex:

How to Alter sequence:

Syntax: Alter sequence seq_name

(conditions…….);

Ex:

How to Drop Sequence: 

Syntax: Drop sequence sequence_name

Ex:

 

Thank you for giving your valuable time to read the above information.

If you want to be updated with all our articles send us the Invitation or Follow us:

Ramkumar’s LinkedIn: https://www.linkedin.com/in/ramkumardba/
LinkedIn Group: https://www.linkedin.com/in/ramkumar-m-0061a0204/
Facebook Page: https://www.facebook.com/Oracleagent-344577549964301
Ramkumar’s Twitter: https://twitter.com/ramkuma02877110
Ramkumar’s Telegram: https://t.me/oracleageant
Ramkumar’s Facebook: https://www.facebook.com/ramkumarram8