Adding sequence to a table

Author:

This TIP can be used to add a sequence in a column for a table

The syntax for creating a sequence is

 CREATE SEQUENCE sequence_name
    MINVALUE value
    MAXVALUE value
    START WITH value
    INCREMENT BY value
    CACHE value;

The steps are

–create table with a column

create table tickets3(s_no  integer);

— create a sequence , Option 1
CREATE SEQUENCE tickets_rid_seq;

— create a sequence , Option 2

CREATE SEQUENCE supplier_seq
    MINVALUE 1
    MAXVALUE 999999999999999999999999999
    START WITH 1
    INCREMENT BY 1
    CACHE 20;

–Update the column with the sequence that was created last

UPDATE tickets3 SET s_no = tickets_rid_seq.nextval;

–Insert a data in a column using sequence

INSERT INTO suppliers
(supplier_id, supplier_name)
VALUES
(supplier_seq.nextval, ‘Kraft Foods’);

for more reference

http://www.techonthenet.com/oracle/sequences.php

Leave a Reply

Your email address will not be published.