- •Objectivesj i
- •Modifyingi i a Sequence
- •Database Objectsj
- •What IsIs a Sequence?
- •The CREATE SEQUENCE
- •Creatingi a Sequence
- •Confirmingi i Sequences
- •NEXTVAL and CURRVAL Pseudocolumnsl
- •Usingi a Sequence
- •Usingi a Sequence
- •Guidelinesi li for Modifyingi i a Sequence
- •Removingi a Sequence
- •What IsIs an Index?I
- •How Are IndexesI Created?
- •Creatingi an IndexI
- •Guidelinesi li to Creatingi an IndexI
- •Guidelinesi li to Creatingi an IndexI
- •Confirmingi i IndexesI
- •Removingi an IndexI
- •Synonyms
- •Creatingi and Removingi Synonyms
- •Summary
- •Practicei Overviewi
Guidelinesi li for Modifyingi i a Sequence
•• You mustt be thet ownerr orr have thet
ALTER privilegeri il forf r thet sequence..
•• Onlyly futuref t re sequence numbersrs arere affectedff t ..
•• The sequence mustt be droppedr and rere--createdr t toto restartr t rt thet sequence att a differentiff r t numberr..
•• Some validationli ti isis performedrf r ..
13-13
Removingi a Sequence
•• Remove a sequence fromfr thet datata dictionaryi ti ry by usingi thet DROP SEQUENCE statementt t t..
•• Once removed,r , thet sequence can no longerl r be referencedr f r ..
SQL> DROP SEQUENCE dept_deptno;
Sequence dropped.
13-14
What IsIs an Index?I
•• Schema objectj t
•• Used by thet Oracler le Serverr r toto speed up thet retrievalr tri l off rowsr by usingi a pointeri t r
•• Reduces diski I/OI/O by usingi rapidr id pathth access methodt toto locatel te thet datata quicklyi ly
•• IndependentI t off thet tablet le itit indexesi
•• Automaticallyt ti lly used and maintainedi t i by thet Oracler le Serverr r
13-15
How Are IndexesI Created?
•• Automaticallyt ti lly
–A uniquei indexi isis createdr t automaticallyt ti lly when you definefi a PRIMARYI KEY orr UNIQUEI key constrainttr i t inin a tablet le definitionfi iti ..
•• Manuallylly
–Usersrs can creater te nonuniquei indexesi
on columnsl toto speed up access timeti toto thet rowsr ..
13-16
Creatingi an IndexI
•• Creater te an indexi on one orr morere columnsl
CREATE INDEX index
ON table (column[, column]...);
•• ImproveI r thet speed off queryry access on thet ENAME columnl inin thet EMP tablet le
|
|
|
|
|
|
SQL> |
CREATE INDEX |
emp_ename_idx |
|
|
2 |
ON |
emp(ename); |
|
|
Index created. |
|
|
|
|
|
|
|
|
13-17
Guidelinesi li to Creatingi an IndexI
•• The columnl isis used frequentlyfre tly inin thet WHERE clausel orr inin a joinj in conditioniti ..
•• The columnl containst i a widei ranger off valuesl ..
•• The columnl containst i a largel r numberr off nullll valuesl ..
•• Two orr morere columnsl arere frequentlyfre tly used togethert t r inin a WHERE clausel orr a joinj in conditioniti ..
•• The tablet le isis largel r and mostt queriesri arere expectedt toto retriever tri lessl thant 2–4% off thet rowsr ..
13-18
Guidelinesi li to Creatingi an IndexI
Do not create an index if:
•• The tablet le isis smallll
•• The columnsl arere nott oftenft used as a conditioniti inin thet queryry
•• Mostt queriesri arere expectedt toto retriever tri morere thant 2–4% off thet rowsr
•• The tablet le isis updatedt frequentlyfre tly
13-19
Confirmingi i IndexesI
•• The USER_INDEXESI datata dictionaryi ti ry viewi containst i thet name off thet indexi and itsits uniquenessi ..
•• The USER_INDI _COLUMNS viewi containst i thet indexi name,, thet tablet le name,, and thet columnl name..
|
|
|
|
|
|
|
|
SQL> SELECT |
ic.index_name, ic.column_name, |
|
|||
|
2 |
|
ic.column_position col_pos,ix.uniqueness |
|
||
|
3 |
FROM |
user_indexes ix, user_ind_columns ic |
|
||
|
4 |
WHERE |
ic.index_name |
= |
ix.index_name |
|
|
5 |
AND |
ic.table_name |
= |
'EMP'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13-20
Removingi an IndexI
•• Remove an indexi fromfr thet datata dictionaryi ti ry..

SQL> DROP INDEX index;
•• Remove thet EMP_ENAME_IDXI indexi fromfr thet datata dictionaryi ti ry..
SQL> DROP INDEX emp_ename_idx;
Index dropped.
•• To dropr an index,i , you mustt be thet ownerr off thet indexi orr have thet DROPANY INDEXI privilegeri il ..
13-21
Synonyms
Simplify access to objects by creating a synonym (another name for an object).
•• Referf r toto a tablet le owned by anothert r userr..
•• Shortenrt lengthyl t objectj t names..
CREATE [PUBLIC] SYNONYM synonym
FOR object;
13-22
