Sequence_1.htm
Sequence: A sequence is a set of numbers that would increase or decrease with a specified and unique  orders.

This helps the developer to maintain or generate unique number (column/field) of a dynamically managed table.

SQL> drop sequence first_seq;

Sequence dropped.

SQL> drop sequence sec_seq;

Sequence dropped.

SQL> create sequence first_seq
2 start with 1
3 increment by 1
4 nomaxvalue;

Sequence created.

SQL> create sequence sec_seq
2 start with 1
3 increment by 1
4 nomaxvalue;

Sequence created.

SQL>
SQL> CREATE TABLE p_firstnormal
2 ( p_id number(2) not null,
3 p_name varchar2(10) not null,
4 age number(2) not null,
5 address varchar2(30),
6 city varchar2(20),
7 state varchar2(2),
8 CONSTRAINT p_pk PRIMARY KEY (p_id,p_name )
9 );

Table created.

SQL>
SQL> CREATE TABLE p_position
2 ( p_id number(2) not null,
3 p_name varchar2(10) not null,
4 position varchar2(10),
5 CONSTRAINT position_fk
6 foreign key (p_id, p_name) references p_firstnormal(p_id,p_name));

Table created.

SQL> prompt iserting data p_fristnormal
iserting data p_fristnormal
SQL> insert into p_firstnormal (p_id,p_name,age,address,city,state) values(first_seq.nextval,'Anthon
y',12,'123 ABC street','Bloomingdale','IL');

1 row created.

SQL> insert into p_firstnormal (p_id,p_name,age,address,city,state) values(first_seq.nextval,'Beth',
13,'456 New street','Bloomingdale','IL');

1 row created.

SQL> insert into p_firstnormal (p_id,p_name,age,address,city,state) values(first_seq.nextval,'Carlos
',11,'123 Another street','Bloomingdale','IL');

1 row created.

SQL> insert into p_firstnormal (p_id,p_name,age,address,city,state) values(first_seq.nextval,'Daniel
',11,'123 Tatek street','Bloomingdale','IL');

1 row created.

SQL>
SQL> insert into p_position (p_id,p_name,position) values(sec_seq.nextval,'Anthony','center-d');

1 row created.

SQL> insert into p_position (p_id,p_name,position) values(sec_seq.nextval,'Beth','center-mid');

1 row created.

SQL> insert into p_position (p_id,p_name,position) values(sec_seq.nextval,'Carlos','left-d');

1 row created.

SQL> insert into p_position (p_id,p_name,position) values(sec_seq.nextval,'Daniel','right-d');

1 row created.

SQL>
SQL> select constraint_name, constraint_type
2 from user_constraints
3 where table_name ='P_FIRSTNORMAL';

CONSTRAINT_NAME       C
--------------------------------------- -
SYS_C005978                        C
SYS_C005979                        C
SYS_C005980                        C
P_PK                                      P

SQL> select constraint_name, constraint_type
2 from user_constraints
3 where table_name ='P_POSITION';

CONSTRAINT_NAME     C
------------------------------ -
SYS_C005982                      C
SYS_C005983                      C
POSITION_FK                    R

SQL>