You are on page 1of 3

SEQUENCES

A Sequence is a database object that generates unique integer numbers in


sequential order.

Sequences are used to generate primary key values or unique key values
automatically either in ascending or descending order.

Some DBMS like MySQL supports AUTO_INCREMENT in place of Sequence.


AUTO_INCREMENT is applied on columns, it automatically increments the column
value by 1 each time a new record is entered into the table.

Sequence is also somewhat similar to AUTO_INCREMENT but it has some extra


features in Oracle.

Parameters to create sequence


Initial-value - specifies the starting value of the Sequence,
Increment-value - is the value by which sequence will be incremented
Maxvalue - specifies the maximum value until which sequence will increment itself.
Cycle - specifies that if the maximum value exceeds the set limit, sequence will restart its
cycle from the beginning.
No cycle - specifies that if sequence exceeds maxvalue an error will be thrown.

Syntax to create sequences is


CREATE SEQUENCE sequence-name
START WITH initial-value
INCREMENT BY increment-value
MAXVALUE maximum-value
CYCLE|NOCYCLE;

Example to create Sequence


CREATE SEQUENCE seq_1
START WITH 1
INCREMENT BY 1
MAXVALUE 999
CYCLE;

Synonyms
Synonyms provide both data independence and location transparency.
Synonyms permit applications to function without modification
regardless of which user owns the table or view and regardless of
which database holds the table or view.
However, synonyms are not a substitute for privileges on database
objects. Appropriate privileges must be granted to a user before the
user can use the synonym.
There are two major uses of synonyms:
o Object invisibility: Synonyms can be created to keep the
original object hidden from the user.
o Location invisibility: Synonyms can be created as aliases
for tables and other objects that are not part of the local
database.

Types of Synonyms
1) Public synonyms
2) Private synonyms

Syntax to create Synonym


CREATE [or replace] [public] SYNONYM [schema.] synonym_name FOR [schema.]
object_name;

Example
create public synonym suppliers

for app.suppliers;

Snapshots:
Snapshots in Oracle work like views but with a small difference. When views are created
database stores only the query defining the view. In contrast, a snapshot is a view whose
contents are computed and stored.
Snapshot constitute redundant data, in that their contents can be inferred from the view
definition and the rest of the database contents. However, it is much cheaper in many cases to
read the contents of a Snapshot than to compute the contents of the view by executing the
query defining the view.

Syntax:
CREATE SNAPSHOT Snapshot Name<option list> AS <SQL query>;

Example:
Create snapshot snap1 as select * from emp;

You might also like