Vous êtes sur la page 1sur 8

Chapter 4

ADVANCE SQL : SQL Performance Tuning


Marks = 12

4.1 Views: What are Views? The Create View Command, Updating Views,
Views and Joins, Views and Sub queries, What Views cannot do? , Dropping
Views.
4.2 Sequences: Creating Sequences, Altering Sequences, Dropping Sequences.
4.3 Indexes: Index Types, Creating of an Index: Simple Unique, and Composite
Index, Dropping Indexes.
4.4 Snapshots: Creating a Snapshot, Altering Snapshot, Dropping a Snapshot.
4.5 Synonyms: Creating a Synonyms, Dropping a Synonyms.

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 some what similar to AUTO_INCREMENT but its 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
Public synonyms 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 SnapshotName<option
list> as <SQL query>;
Example : Create snapshot snap1 as select *from
Emp;

Vous aimerez peut-être aussi