SlideShare a Scribd company logo
Copyright ‫س‬ Oracle Corporation, 1998. All rights reserved.
13
Other Database Objects
13-2 Copyright ‫س‬ Oracle Corporation, 1998. All rights reserved.
Objectives
After completing this lesson, you should
be able to do the following:
• Describe some database objects and
their uses
• Create, maintain, and use sequences
• Create and maintain indexes
• Create private and public synonyms
13-3 Copyright ‫س‬ Oracle Corporation, 1998. All rights reserved.
Database Objects
Description
Basic unit of storage; composed of rows
and columns
Logically represents subsets of data from
one or more tables
Generates primary key values
Improves the performance of some queries
Alternative name for an object
Object
Table
View
Sequence
Index
Synonym
13-4 Copyright ‫س‬ Oracle Corporation, 1998. All rights reserved.
What Is a Sequence?
• Automatically generates unique
numbers
• Is a sharable object
• Is typically used to create a primary key
value
• Replaces application code
• Speeds up the efficiency of accessing
sequence values when cached in
memory
13-5 Copyright ‫س‬ Oracle Corporation, 1998. All rights reserved.
The CREATE SEQUENCE
Statement
Define a sequence to generate sequential
numbers automatically.
CREATE SEQUENCE sequence
[INCREMENT BY n]
[START WITH n]
[{MAXVALUE n | NOMAXVALUE}]
[{MINVALUE n | NOMINVALUE}]
[{CYCLE | NOCYCLE}]
[{CACHE n | NOCACHE}];
13-6 Copyright ‫س‬ Oracle Corporation, 1998. All rights reserved.
Creating a Sequence
• Create a sequence named DEPT_DEPTNO
to be used for the primary key of the
DEPT table.
• Do not use the CYCLE option.
SQL> CREATE SEQUENCE dept_deptno
2 INCREMENT BY 1
3 START WITH 91
4 MAXVALUE 100
5 NOCACHE
6 NOCYCLE;
Sequence created.
13-7 Copyright ‫س‬ Oracle Corporation, 1998. All rights reserved.
Confirming Sequences
• Verify your sequence values in the
USER_SEQUENCES data dictionary
table.
• The LAST_NUMBER column displays
the next available sequence number.
SQL> SELECT sequence_name, min_value, max_value,
2 increment_by, last_number
3 FROM user_sequences;
13-8 Copyright ‫س‬ Oracle Corporation, 1998. All rights reserved.
NEXTVAL and CURRVAL
Pseudocolumns
• NEXTVAL returns the next available
sequence value.
It returns a unique value every time it is
referenced, even for different users.
• CURRVAL obtains the current sequence
value.
NEXTVAL must be issued for that
sequence before CURRVAL contains a
value.
13-10 Copyright ‫س‬ Oracle Corporation, 1998. All rights reserved.
Using a Sequence
• Insert a new department named
“MARKETING” in San Diego.
• View the current value for the
DEPT_DEPTNO sequence.
SQL> INSERT INTO dept(deptno, dname, loc)
2 VALUES (dept_deptno.NEXTVAL,
3 'MARKETING', 'SAN DIEGO');
1 row created.
SQL> SELECT dept_deptno.CURRVAL
2 FROM dual;
13-11 Copyright ‫س‬ Oracle Corporation, 1998. All rights reserved.
Using a Sequence
• Caching sequence values in memory
allows faster access to those values.
• Gaps in sequence values can occur when:
– A rollback occurs
– The system crashes
– A sequence is used in another table
• View the next available sequence, if it was
created with NOCACHE, by querying the
USER_SEQUENCES table.
13-12 Copyright ‫س‬ Oracle Corporation, 1998. All rights reserved.
Modifying a Sequence
Change the increment value, maximum
value, minimum value, cycle option, or
cache option.
SQL> ALTER SEQUENCE dept_deptno
2 INCREMENT BY 1
3 MAXVALUE 999999
4 NOCACHE
5 NOCYCLE;
Sequence altered.
13-13 Copyright ‫س‬ Oracle Corporation, 1998. All rights reserved.
Guidelines for Modifying
a Sequence
• You must be the owner or have the
ALTER privilege for the sequence.
• Only future sequence numbers are
affected.
• The sequence must be dropped and
re-created to restart the sequence at a
different number.
• Some validation is performed.
13-14 Copyright ‫س‬ Oracle Corporation, 1998. All rights reserved.
Removing a Sequence
• Remove a sequence from the data
dictionary by using the DROP
SEQUENCE statement.
• Once removed, the sequence can no
longer be referenced.
SQL> DROP SEQUENCE dept_deptno;
Sequence dropped.
13-15 Copyright ‫س‬ Oracle Corporation, 1998. All rights reserved.
What Is an Index?
• Is a schema object
• Is used by the Oracle Server to speed
up the retrieval of rows by using a
pointer
• Can reduce disk I/O by using rapid path
access method to locate the data
quickly
• Is independent of the table it indexes
• Is used and maintained automatically by
the Oracle Server
13-16 Copyright ‫س‬ Oracle Corporation, 1998. All rights reserved.
How Are Indexes Created?
• Automatically: A unique index is
created automatically when you define a
PRIMARY KEY or UNIQUE constraint in
a table definition.
• Manually: Users can create nonunique
indexes on columns to speed up access
time to the rows.
13-17 Copyright ‫س‬ Oracle Corporation, 1998. All rights reserved.
Creating an Index
• Improve the speed of query access on
the ENAME column in the EMP table.
SQL> CREATE INDEX emp_ename_idx
2 ON emp(ename);
Index created.
CREATE INDEX index
ON table (column[, column]...);
• Create an index on one or more columns.
13-18 Copyright ‫س‬ Oracle Corporation, 1998. All rights reserved.
When to Create an Index
• The column is used frequently in the WHERE
clause or in a join condition.
• The column contains a wide range of values.
• The column contains a large number of null
values.
• Two or more columns are frequently used
together in a WHERE clause or a join
condition.
• The table is large and most queries are
expected to retrieve less than 2–4% of the
rows.
13-19 Copyright ‫س‬ Oracle Corporation, 1998. All rights reserved.
When Not to Create an Index
• The table is small.
• The columns are not often used as a
condition in the query.
• Most queries are expected to retrieve
more than 2–4% of the rows.
• The table is updated frequently.
13-20 Copyright ‫س‬ Oracle Corporation, 1998. All rights reserved.
Confirming Indexes
• The USER_INDEXES data dictionary view
contains the name of the index and its
uniqueness.
• The USER_IND_COLUMNS view contains
the index name, the table name, and the
column 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-21 Copyright ‫س‬ Oracle Corporation, 1998. All rights reserved.
Removing an Index
• Remove an index from the data dictionary.
• Remove the EMP_ENAME_IDX index from
the data dictionary.
• To drop an index, you must be the owner
of the index or have the DROP ANY INDEX
privilege.
SQL> DROP INDEX emp_ename_idx;
Index dropped.
SQL> DROP INDEX index;
13-22 Copyright ‫س‬ Oracle Corporation, 1998. All rights reserved.
Synonyms
Simplify access to objects by creating a
synonym (another name for an object).
• Refer to a table owned by another user.
• Shorten lengthy object names.
CREATE [PUBLIC] SYNONYM synonym
FOR object;
13-23 Copyright ‫س‬ Oracle Corporation, 1998. All rights reserved.
Creating and Removing Synonyms
SQL> CREATE SYNONYM d_sum
2 FOR dept_sum_vu;
Synonym Created.
SQL> DROP SYNONYM d_sum;
Synonym dropped.
• Create a shortened name for the
DEPT_SUM_VU view.
• Drop a synonym.
13-24 Copyright ‫س‬ Oracle Corporation, 1998. All rights reserved.
Summary
• Automatically generate sequence
numbers by using a sequence generator.
• View sequence information in the
USER_SEQUENCES data dictionary table.
• Create indexes to improve query retrieval
speed.
• View index information in the
USER_INDEXES dictionary table.
• Use synonyms to provide alternative
names for objects.
13-25 Copyright ‫س‬ Oracle Corporation, 1998. All rights reserved.
Practice Overview
• Creating sequences
• Using sequences
• Creating nonunique indexes
• Displaying data dictionary information
about sequences and indexes
• Dropping indexes

More Related Content

What's hot

Nested Queries Lecture
Nested Queries LectureNested Queries Lecture
Nested Queries Lecture
Felipe Costa
 
Triggers in SQL | Edureka
Triggers in SQL | EdurekaTriggers in SQL | Edureka
Triggers in SQL | Edureka
Edureka!
 
PL/SQL TRIGGERS
PL/SQL TRIGGERSPL/SQL TRIGGERS
PL/SQL TRIGGERS
Lakshman Basnet
 
Sql clauses by Manan Pasricha
Sql clauses by Manan PasrichaSql clauses by Manan Pasricha
Sql clauses by Manan Pasricha
MananPasricha
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
baabtra.com - No. 1 supplier of quality freshers
 
Sql commands
Sql commandsSql commands
Sql commands
Pooja Dixit
 
Triggers
TriggersTriggers
Triggers
Pooja Dixit
 
MySQL
MySQLMySQL
02 Writing Executable Statments
02 Writing Executable Statments02 Writing Executable Statments
02 Writing Executable Statments
rehaniltifat
 
Database programming in vb net
Database programming in vb netDatabase programming in vb net
Database programming in vb netZishan yousaf
 
Create table
Create tableCreate table
Create table
Nitesh Singh
 
SQL
SQLSQL
PL/SQL - CURSORS
PL/SQL - CURSORSPL/SQL - CURSORS
PL/SQL - CURSORS
IshaRana14
 
Introduction to structured query language (sql)
Introduction to structured query language (sql)Introduction to structured query language (sql)
Introduction to structured query language (sql)
Sabana Maharjan
 
SQL(DDL & DML)
SQL(DDL & DML)SQL(DDL & DML)
SQL(DDL & DML)
Sharad Dubey
 
DATABASE CONSTRAINTS
DATABASE CONSTRAINTSDATABASE CONSTRAINTS
DATABASE CONSTRAINTS
sunanditaAnand
 

What's hot (20)

SQL Constraints
SQL ConstraintsSQL Constraints
SQL Constraints
 
Nested Queries Lecture
Nested Queries LectureNested Queries Lecture
Nested Queries Lecture
 
Triggers in SQL | Edureka
Triggers in SQL | EdurekaTriggers in SQL | Edureka
Triggers in SQL | Edureka
 
PL/SQL TRIGGERS
PL/SQL TRIGGERSPL/SQL TRIGGERS
PL/SQL TRIGGERS
 
Sql clauses by Manan Pasricha
Sql clauses by Manan PasrichaSql clauses by Manan Pasricha
Sql clauses by Manan Pasricha
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
Sql commands
Sql commandsSql commands
Sql commands
 
Triggers
TriggersTriggers
Triggers
 
MySQL
MySQLMySQL
MySQL
 
02 Writing Executable Statments
02 Writing Executable Statments02 Writing Executable Statments
02 Writing Executable Statments
 
Database programming in vb net
Database programming in vb netDatabase programming in vb net
Database programming in vb net
 
MYSQL.ppt
MYSQL.pptMYSQL.ppt
MYSQL.ppt
 
Create table
Create tableCreate table
Create table
 
Mysql
MysqlMysql
Mysql
 
SQL
SQLSQL
SQL
 
PL/SQL - CURSORS
PL/SQL - CURSORSPL/SQL - CURSORS
PL/SQL - CURSORS
 
Introduction to structured query language (sql)
Introduction to structured query language (sql)Introduction to structured query language (sql)
Introduction to structured query language (sql)
 
SQL(DDL & DML)
SQL(DDL & DML)SQL(DDL & DML)
SQL(DDL & DML)
 
DATABASE CONSTRAINTS
DATABASE CONSTRAINTSDATABASE CONSTRAINTS
DATABASE CONSTRAINTS
 

Similar to Sequences and indexes

chap13.ppt
chap13.pptchap13.ppt
Les13[1]Other Database Objects
Les13[1]Other Database ObjectsLes13[1]Other Database Objects
Les13[1]Other Database Objects
siavosh kaviani
 
SQL WORKSHOP::Lecture 13
SQL WORKSHOP::Lecture 13SQL WORKSHOP::Lecture 13
SQL WORKSHOP::Lecture 13Umair Amjad
 
Database Objects
Database ObjectsDatabase Objects
Database Objects
Salman Memon
 
Less07 schema
Less07 schemaLess07 schema
Less07 schemaImran Ali
 
Less08_Schema Advanced Databases and Management.pptx
Less08_Schema Advanced Databases and Management.pptxLess08_Schema Advanced Databases and Management.pptx
Less08_Schema Advanced Databases and Management.pptx
MurtazaMughal13
 
Les11.ppt
Les11.pptLes11.ppt
Sql views
Sql viewsSql views
Sql views
arshid045
 
Oracle notes
Oracle notesOracle notes
Oracle notes
Prashant Dadmode
 
Creating and Managing Tables -Oracle Data base
Creating and Managing Tables -Oracle Data base Creating and Managing Tables -Oracle Data base
Creating and Managing Tables -Oracle Data base
Salman Memon
 
Introduction to SQL, SQL*Plus
Introduction to SQL, SQL*PlusIntroduction to SQL, SQL*Plus
Introduction to SQL, SQL*Plus
Chhom Karath
 
03 Writing Control Structures, Writing with Compatible Data Types Using Expli...
03 Writing Control Structures, Writing with Compatible Data Types Using Expli...03 Writing Control Structures, Writing with Compatible Data Types Using Expli...
03 Writing Control Structures, Writing with Compatible Data Types Using Expli...
rehaniltifat
 
Overview of Oracle database12c for developers
Overview of Oracle database12c for developersOverview of Oracle database12c for developers
Overview of Oracle database12c for developers
Getting value from IoT, Integration and Data Analytics
 
08 Dynamic SQL and Metadata
08 Dynamic SQL and Metadata08 Dynamic SQL and Metadata
08 Dynamic SQL and Metadata
rehaniltifat
 
Sql lite android
Sql lite androidSql lite android
Sql lite android
Dushyant Nasit
 
Les10[1]Creating and Managing Tables
Les10[1]Creating and Managing TablesLes10[1]Creating and Managing Tables
Les10[1]Creating and Managing Tables
siavosh kaviani
 

Similar to Sequences and indexes (20)

chap13.ppt
chap13.pptchap13.ppt
chap13.ppt
 
Les13[1]Other Database Objects
Les13[1]Other Database ObjectsLes13[1]Other Database Objects
Les13[1]Other Database Objects
 
SQL WORKSHOP::Lecture 13
SQL WORKSHOP::Lecture 13SQL WORKSHOP::Lecture 13
SQL WORKSHOP::Lecture 13
 
Database Objects
Database ObjectsDatabase Objects
Database Objects
 
Les10
Les10Les10
Les10
 
Less07 schema
Less07 schemaLess07 schema
Less07 schema
 
Less08_Schema Advanced Databases and Management.pptx
Less08_Schema Advanced Databases and Management.pptxLess08_Schema Advanced Databases and Management.pptx
Less08_Schema Advanced Databases and Management.pptx
 
Les11.ppt
Les11.pptLes11.ppt
Les11.ppt
 
Les13
Les13Les13
Les13
 
Sql views
Sql viewsSql views
Sql views
 
Oracle notes
Oracle notesOracle notes
Oracle notes
 
Creating and Managing Tables -Oracle Data base
Creating and Managing Tables -Oracle Data base Creating and Managing Tables -Oracle Data base
Creating and Managing Tables -Oracle Data base
 
Introduction to SQL, SQL*Plus
Introduction to SQL, SQL*PlusIntroduction to SQL, SQL*Plus
Introduction to SQL, SQL*Plus
 
03 Writing Control Structures, Writing with Compatible Data Types Using Expli...
03 Writing Control Structures, Writing with Compatible Data Types Using Expli...03 Writing Control Structures, Writing with Compatible Data Types Using Expli...
03 Writing Control Structures, Writing with Compatible Data Types Using Expli...
 
Les09.ppt
Les09.pptLes09.ppt
Les09.ppt
 
Overview of Oracle database12c for developers
Overview of Oracle database12c for developersOverview of Oracle database12c for developers
Overview of Oracle database12c for developers
 
08 Dynamic SQL and Metadata
08 Dynamic SQL and Metadata08 Dynamic SQL and Metadata
08 Dynamic SQL and Metadata
 
Sql lite android
Sql lite androidSql lite android
Sql lite android
 
Les10[1]Creating and Managing Tables
Les10[1]Creating and Managing TablesLes10[1]Creating and Managing Tables
Les10[1]Creating and Managing Tables
 
Les12
Les12Les12
Les12
 

More from Balqees Al.Mubarak

Using scripts
Using scriptsUsing scripts
Using scripts
Balqees Al.Mubarak
 
Single row functions
Single row functionsSingle row functions
Single row functions
Balqees Al.Mubarak
 
Oracle views
Oracle viewsOracle views
Oracle views
Balqees Al.Mubarak
 
Lab5 sub query
Lab5   sub queryLab5   sub query
Lab5 sub query
Balqees Al.Mubarak
 
Lab4 join - all types listed
Lab4   join - all types listedLab4   join - all types listed
Lab4 join - all types listed
Balqees Al.Mubarak
 
Lab3 aggregating data
Lab3   aggregating dataLab3   aggregating data
Lab3 aggregating data
Balqees Al.Mubarak
 
Lab2 ddl commands
Lab2 ddl commandsLab2 ddl commands
Lab2 ddl commands
Balqees Al.Mubarak
 
Lab1 select statement
Lab1 select statementLab1 select statement
Lab1 select statement
Balqees Al.Mubarak
 

More from Balqees Al.Mubarak (9)

Using scripts
Using scriptsUsing scripts
Using scripts
 
Single row functions
Single row functionsSingle row functions
Single row functions
 
Oracle views
Oracle viewsOracle views
Oracle views
 
Lab5 sub query
Lab5   sub queryLab5   sub query
Lab5 sub query
 
Lab4 join - all types listed
Lab4   join - all types listedLab4   join - all types listed
Lab4 join - all types listed
 
Lab3 aggregating data
Lab3   aggregating dataLab3   aggregating data
Lab3 aggregating data
 
Lab2 ddl commands
Lab2 ddl commandsLab2 ddl commands
Lab2 ddl commands
 
Lab1 select statement
Lab1 select statementLab1 select statement
Lab1 select statement
 
Using social network sites
Using social network sites Using social network sites
Using social network sites
 

Recently uploaded

Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
AzmatAli747758
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
Celine George
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
Celine George
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
EduSkills OECD
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
Nguyen Thanh Tu Collection
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
bennyroshan06
 

Recently uploaded (20)

Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 

Sequences and indexes

  • 1. Copyright ‫س‬ Oracle Corporation, 1998. All rights reserved. 13 Other Database Objects
  • 2. 13-2 Copyright ‫س‬ Oracle Corporation, 1998. All rights reserved. Objectives After completing this lesson, you should be able to do the following: • Describe some database objects and their uses • Create, maintain, and use sequences • Create and maintain indexes • Create private and public synonyms
  • 3. 13-3 Copyright ‫س‬ Oracle Corporation, 1998. All rights reserved. Database Objects Description Basic unit of storage; composed of rows and columns Logically represents subsets of data from one or more tables Generates primary key values Improves the performance of some queries Alternative name for an object Object Table View Sequence Index Synonym
  • 4. 13-4 Copyright ‫س‬ Oracle Corporation, 1998. All rights reserved. What Is a Sequence? • Automatically generates unique numbers • Is a sharable object • Is typically used to create a primary key value • Replaces application code • Speeds up the efficiency of accessing sequence values when cached in memory
  • 5. 13-5 Copyright ‫س‬ Oracle Corporation, 1998. All rights reserved. The CREATE SEQUENCE Statement Define a sequence to generate sequential numbers automatically. CREATE SEQUENCE sequence [INCREMENT BY n] [START WITH n] [{MAXVALUE n | NOMAXVALUE}] [{MINVALUE n | NOMINVALUE}] [{CYCLE | NOCYCLE}] [{CACHE n | NOCACHE}];
  • 6. 13-6 Copyright ‫س‬ Oracle Corporation, 1998. All rights reserved. Creating a Sequence • Create a sequence named DEPT_DEPTNO to be used for the primary key of the DEPT table. • Do not use the CYCLE option. SQL> CREATE SEQUENCE dept_deptno 2 INCREMENT BY 1 3 START WITH 91 4 MAXVALUE 100 5 NOCACHE 6 NOCYCLE; Sequence created.
  • 7. 13-7 Copyright ‫س‬ Oracle Corporation, 1998. All rights reserved. Confirming Sequences • Verify your sequence values in the USER_SEQUENCES data dictionary table. • The LAST_NUMBER column displays the next available sequence number. SQL> SELECT sequence_name, min_value, max_value, 2 increment_by, last_number 3 FROM user_sequences;
  • 8. 13-8 Copyright ‫س‬ Oracle Corporation, 1998. All rights reserved. NEXTVAL and CURRVAL Pseudocolumns • NEXTVAL returns the next available sequence value. It returns a unique value every time it is referenced, even for different users. • CURRVAL obtains the current sequence value. NEXTVAL must be issued for that sequence before CURRVAL contains a value.
  • 9. 13-10 Copyright ‫س‬ Oracle Corporation, 1998. All rights reserved. Using a Sequence • Insert a new department named “MARKETING” in San Diego. • View the current value for the DEPT_DEPTNO sequence. SQL> INSERT INTO dept(deptno, dname, loc) 2 VALUES (dept_deptno.NEXTVAL, 3 'MARKETING', 'SAN DIEGO'); 1 row created. SQL> SELECT dept_deptno.CURRVAL 2 FROM dual;
  • 10. 13-11 Copyright ‫س‬ Oracle Corporation, 1998. All rights reserved. Using a Sequence • Caching sequence values in memory allows faster access to those values. • Gaps in sequence values can occur when: – A rollback occurs – The system crashes – A sequence is used in another table • View the next available sequence, if it was created with NOCACHE, by querying the USER_SEQUENCES table.
  • 11. 13-12 Copyright ‫س‬ Oracle Corporation, 1998. All rights reserved. Modifying a Sequence Change the increment value, maximum value, minimum value, cycle option, or cache option. SQL> ALTER SEQUENCE dept_deptno 2 INCREMENT BY 1 3 MAXVALUE 999999 4 NOCACHE 5 NOCYCLE; Sequence altered.
  • 12. 13-13 Copyright ‫س‬ Oracle Corporation, 1998. All rights reserved. Guidelines for Modifying a Sequence • You must be the owner or have the ALTER privilege for the sequence. • Only future sequence numbers are affected. • The sequence must be dropped and re-created to restart the sequence at a different number. • Some validation is performed.
  • 13. 13-14 Copyright ‫س‬ Oracle Corporation, 1998. All rights reserved. Removing a Sequence • Remove a sequence from the data dictionary by using the DROP SEQUENCE statement. • Once removed, the sequence can no longer be referenced. SQL> DROP SEQUENCE dept_deptno; Sequence dropped.
  • 14. 13-15 Copyright ‫س‬ Oracle Corporation, 1998. All rights reserved. What Is an Index? • Is a schema object • Is used by the Oracle Server to speed up the retrieval of rows by using a pointer • Can reduce disk I/O by using rapid path access method to locate the data quickly • Is independent of the table it indexes • Is used and maintained automatically by the Oracle Server
  • 15. 13-16 Copyright ‫س‬ Oracle Corporation, 1998. All rights reserved. How Are Indexes Created? • Automatically: A unique index is created automatically when you define a PRIMARY KEY or UNIQUE constraint in a table definition. • Manually: Users can create nonunique indexes on columns to speed up access time to the rows.
  • 16. 13-17 Copyright ‫س‬ Oracle Corporation, 1998. All rights reserved. Creating an Index • Improve the speed of query access on the ENAME column in the EMP table. SQL> CREATE INDEX emp_ename_idx 2 ON emp(ename); Index created. CREATE INDEX index ON table (column[, column]...); • Create an index on one or more columns.
  • 17. 13-18 Copyright ‫س‬ Oracle Corporation, 1998. All rights reserved. When to Create an Index • The column is used frequently in the WHERE clause or in a join condition. • The column contains a wide range of values. • The column contains a large number of null values. • Two or more columns are frequently used together in a WHERE clause or a join condition. • The table is large and most queries are expected to retrieve less than 2–4% of the rows.
  • 18. 13-19 Copyright ‫س‬ Oracle Corporation, 1998. All rights reserved. When Not to Create an Index • The table is small. • The columns are not often used as a condition in the query. • Most queries are expected to retrieve more than 2–4% of the rows. • The table is updated frequently.
  • 19. 13-20 Copyright ‫س‬ Oracle Corporation, 1998. All rights reserved. Confirming Indexes • The USER_INDEXES data dictionary view contains the name of the index and its uniqueness. • The USER_IND_COLUMNS view contains the index name, the table name, and the column 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';
  • 20. 13-21 Copyright ‫س‬ Oracle Corporation, 1998. All rights reserved. Removing an Index • Remove an index from the data dictionary. • Remove the EMP_ENAME_IDX index from the data dictionary. • To drop an index, you must be the owner of the index or have the DROP ANY INDEX privilege. SQL> DROP INDEX emp_ename_idx; Index dropped. SQL> DROP INDEX index;
  • 21. 13-22 Copyright ‫س‬ Oracle Corporation, 1998. All rights reserved. Synonyms Simplify access to objects by creating a synonym (another name for an object). • Refer to a table owned by another user. • Shorten lengthy object names. CREATE [PUBLIC] SYNONYM synonym FOR object;
  • 22. 13-23 Copyright ‫س‬ Oracle Corporation, 1998. All rights reserved. Creating and Removing Synonyms SQL> CREATE SYNONYM d_sum 2 FOR dept_sum_vu; Synonym Created. SQL> DROP SYNONYM d_sum; Synonym dropped. • Create a shortened name for the DEPT_SUM_VU view. • Drop a synonym.
  • 23. 13-24 Copyright ‫س‬ Oracle Corporation, 1998. All rights reserved. Summary • Automatically generate sequence numbers by using a sequence generator. • View sequence information in the USER_SEQUENCES data dictionary table. • Create indexes to improve query retrieval speed. • View index information in the USER_INDEXES dictionary table. • Use synonyms to provide alternative names for objects.
  • 24. 13-25 Copyright ‫س‬ Oracle Corporation, 1998. All rights reserved. Practice Overview • Creating sequences • Using sequences • Creating nonunique indexes • Displaying data dictionary information about sequences and indexes • Dropping indexes