Загрузка...

how to create a sequence in sql oracle

how to create a sequence in sql oracle?

let us first understand what is sequence.

-it is a user created database object that can be shared by multiple users to generate integers.
-it is used for generating unique numbers automatically.
-used to create primary key values.

SYNTAX:

CREATE SEQUENCE sequence_name
START WITH initial_value
INCREMENTED BY increment_value
MINVALUE minimun value
MAXVALUE maximum value
CYCLE|NOCYCLE
STEP 1--------------------------------------------

now before creating a sequence lets create a table first...

create table managers(
col1 number(5)primary key,
col2 varchar2(20));

Name Null Type
---- -------- ------------
COL1 NOT NULL NUMBER(5)
COL2 VARCHAR2(20)
table created.

STEP 2--------------------------------------------

now lets move on to make a sequence using the above syntax..

create sequence manager_a
start with 10
increment by 10
maxvalue 100
minvalue 1
nocycle;

this sequence is with nocycle....lets create one more sequence with cycle...

create sequence manager_b
start with 100
increment by -2
maxvalue 100
minvalue 2
cycle;

now we have created 2 sequences....lets insert it.

STEP 3---------------------------------------------

insert into managers values(manager_a.nextval,manager_b.nextval);

by using this string we have inserted 5 values..

STEP 4-------------------------------------------

lets check it in the table.

so here we have successfully created 2 sequences one with minus incremented value and other with add values.
thanks for watching.

do like share and subscribe.

Видео how to create a sequence in sql oracle канала Oracle Training-Free Oracle Tutorials
Яндекс.Метрика
Все заметки Новая заметка Страницу в заметки
Страницу в закладки Мои закладки
На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.
О CookiesНапомнить позжеПринять