Home arrow Databases arrow Adding sequence to a table
Main Menu
Home
Help Docs
Newbies
Corporates
Gnu/Linux Distros
Programming
Databases
Links
Search
Regular
News
Interviews
Aaj Ka Tip
Aaj Ka Command
Community
Blogs
Wiki
Forums
Services
Free Software

Adding sequence to a table Print E-mail

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

< Previous   Next >



gnulinuxclub
Join Us
About Us
Contact Us
Support Us
Acknowlegdement
Login(only for dev.)

Royalty Free Images

O'Reilly User Group discount!




Powered By GIMP GIMP
Contact Webmaster Copyleft 2011 gnulinuxclub.org