SQL Performance Tunning
SQL Performance Tunning
SQL Performance Tunning
==SEQUENCES.
You can use sequences to automatically generate unique integers OR CIRCLED
INTEGERS.
Sequence created.
syntax
sequencename.nextval
eg.
NEXTVAL
----------
2
SQL> /
NEXTVAL
----------
3
if the sequence runs out of data, you can perform alter.
Sequence altered.
NEXTVAL
----------
21
17 rows updated.
Sequence created.
.................................................................
VIEWS
STORED OBJECT WHICH USED TO CREATE DIFFERENT WINDOWS( ACCESS) OF DATA DEPENDING
ON USER CATEGORY.
EG.
1 row created.
ENAME DEPTNO
---------- ----------
SMITH 20
PAUL 20
GERY 20
SCOTT 20
ADAMS 20
FORD 20
6 rows selected.
ENAME DEPTNO
---------- ----------
SMITH 20
ALLEN 30
WARD 30
PAUL 20
MARTIN 30
BLAKE 30
GERY 20
SCOTT 20
GERY 30
TURNER 30
ADAMS 20
ENAME DEPTNO
---------- ----------
JAMES 30
FORD 20
13 rows selected.
=================================
View created.
EMPNO SAL
---------- ----------
7369 800
7876 2850
EMPNO SAL
---------- ----------
7369 960
7876 3420
EMPNO SAL
---------- ----------
7369 960
7566 3570
7788 3600
7876 2940
7902 3600
View created.
ADD RECORD
7 rows selected.
ENAME SAL
---------- ----------
SMITH 960
ALLEN 1600
WARD 1250
PAUL 2975
MARTIN 1250
BLAKE 2850
GERY
SCOTT 3000
GERY
TURNER 1500
ADAMS 3420
ENAME SAL
---------- ----------
JAMES 2975
FORD 3000
HABIBA 1500
ENAME SAL
---------- ----------
SMITH 960
ALLEN 1600
WARD 1250
MARTIN 1250
TURNER 1500
HABIBA 1500
ENAME SAL
---------- ----------
JAMES 2975
FORD 3000
HABIBA 1500
SELECT*FROM HABIB7;
ENAME SAL DEPTNO
---------- ---------- ----------
SMITH 960 20
PAUL 2975 20
SCOTT 3000 20
FORD 3000 20
View created.
ERROR at line 1:
ORA-42399: cannot perform a DML operation on a read-only view
What is an Index?
UNIQUE indicates that the combination of values in the indexed columns must be
unique.
COMPUTE STATISTICS tells Oracle to collect statistics during the creation of the
index. The statistics are then used by the optimizer to choose a "plan of
execution" when SQL statements are executed.
For Example:
In this example, we've created an index on the supplier table called supplier_idx.
It consists of only one field - the supplier_name field.
We could also create an index with more than one field as in the example below:
We could also choose to collect statistics upon creation of the index as follows:
In Oracle, you are not restricted to creating indexes on only columns. You can
create function-based indexes.
In this example, we've created an index based on the uppercase evaluation of the
supplier_name field.
However, to be sure that the Oracle optimizer uses this index when executing your
SQL statements, be sure that UPPER(supplier_name) does not evaluate to a NULL
value. To ensure this, add UPPER(supplier_name) IS NOT NULL to your WHERE clause as
follows:
Rename an Index
If you forgot to collect statistics on the index when you first created it or you
want to update the statistics, you can always use the ALTER INDEX command to
collect statistics at a later date.
In this example, we're collecting statistics for the index called supplier_idx.
Drop an Index
The syntax for dropping an index is: