DB2 - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

DB2 Sequences

DB2 Sequences

shape Description

DB2 Sequences are the arrangement of whole numbers that are created all together based on appeal. DB2 Sequence will be regularly utilized as a part of databases considering numerous applications requirement that every column in a table to contain an interesting worth and these sequences will be accessible easily. A sequence can be commonly shared between various applications. A DB2 sequence can bolsters the data types such as the INTEGER, BIGINT, SMALLINT, and DECIMAL. It can decremented or incremented the transaction regardless of they values. A DB2 Sequence can be classified into the following types, such as

Next value of a Sequences

These Next value of a sequence rebounds the incremental value for a specific sequence based on numerical representations.

Previous value of a Sequences

The Previous value of a sequence rebounds the newly provoked esteems.

Creating a Sequences

shape Description

A sequence can be created using create sequence method that specifies the INTEGER, BIGINT, SMALLINT, and DECIMAL.

shape Syntax

The syntax for creating a db2 sequence is as follows: 
Create sequence <sequence_name>; Sequence name => Name of the sequence for which the condition has to be applied.

shape Examples

By viewing the below example, the concept of creating a sequence can be easily understood. [c] db2 => create table Item.prod1(prod_id int not null auto_increment,prod_name varchar (25)not null,primary key(prod_id)); SQL executed ok (0.52 sec) db2 => insert into Item.prod1(prod_name) values ('mobile'); SQL executed ok (0.52 sec) db2 => insert into Item.prod1(prod_name) values ('laptop'); SQL executed ok (0.52 sec) db2 => insert into Item.prod1(prod_name) values ('system'); SQL executed ok (0.52 sec) db2 => select * from Item.prod1; +---------+-----------+ | prod_id | prod_name | +---------+-----------+ | 1 | mobile | | 2 | laptop | | 3 | system | +---------+-----------+ 3 record(s) selected[/c]

Summary

shape Key Points

  • DB2 sequence - A sequence is an arrangement of whole numbers generated based on appeals.
  • Types of sequence - Next value and previous value of a sequence.