Database Programming with SQL
16-2: Indexes and Synonyms
Practice Activities
Objectives
• Define an index and its use as a schema object
• Name the conditions that cause an index to be created automatically
• Create and execute a CREATE INDEX and DROP INDEX statement
• Construct and execute a function-based index
• Construct a private and public synonym
Vocabulary
Identify the vocabulary word for each definition below.
Confirms the existence of indexes from the USER_INDEXES
data dictionary view
Schema object that speeds up retrieval of rows
To refer to a table by another name to simplify access
An index that you create on multiple columns in a table
The Oracle Server automatically creates this index when you
define a column in a table to have a PRIMARY KEY or a UNIQUE
KEY constraint
Stores the indexed values and uses the index based on a
SELECT statement to retrieve the data
Removes an index
Gives alternative names to objects
Try It / Solve It
1. What is an index and what is it used for?
2. What is a ROWID, and how is it used?
3. When will an index be created automatically?
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
4. Create a nonunique index (foreign key) for the DJs on Demand column (cd_number) in the
D_TRACK_LISTINGS table. Use the Oracle Application Developer SQL Workshop Data Browser
to confirm that the index was created.
5. Use the join statement to display the indexes and uniqueness that exist in the data dictionary for
the DJs on Demand D_SONGS table.
6. Use a SELECT statement to display the index_name, table_name, and uniqueness from the data
dictionary USER_INDEXES for the DJs on Demand D_EVENTS table.
7. Write a query to create a synonym called dj_tracks for the DJs on Demand d_track_listings table.
8. Create a function-based index for the last_name column in DJs on Demand D_PARTNERS table
that makes it possible not to have to capitalize the table name for searches. Write a SELECT
statement that would use this index.
9. Create a synonym for the D_TRACK_LISTINGS table. Confirm that it has been created by
querying the data dictionary.
10. Drop the synonym that you created in question 9.
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.