Creating Indexes. 15-2 Database Systems Objectives Distinguish between the indexes that are created automatically and those that are created manually.

Slides:



Advertisements
Similar presentations
Creating Tables. 2 home back first prev next last What Will I Learn? List and provide an example of each of the number, character, and date data types.
Advertisements

Copyright  Oracle Corporation, All rights reserved. 10 Creating and Managing Tables.
11-1 Copyright © Oracle Corporation, All rights reserved. Different type of keys.
Introduction to Structured Query Language (SQL)
10 Copyright © 2004, Oracle. All rights reserved. Creating Other Schema Objects.
Introduction to Structured Query Language (SQL)
Copyright س Oracle Corporation, All rights reserved. 13 Other Database Objects.
A Guide to MySQL 7. 2 Objectives Understand, define, and drop views Recognize the benefits of using views Use a view to update data Grant and revoke users’
A Guide to SQL, Seventh Edition. Objectives Understand, create, and drop views Recognize the benefits of using views Grant and revoke user’s database.
SQL's Data Definition Language (DDL) – View, Sequence, Index.
Chapter 6 Additional Database Objects
Constraints  Constraints are used to enforce rules at table level.  Constraints prevent the deletion of a table if there is dependencies.  The following.
13 Other Database Objects Important Legal Notice:  Materials on this lecture are from a book titled “Oracle Education” by Kochhar, Gravina, and Nathan.
Copyright © 2004, Oracle. All rights reserved. Lecture 3: Creating Other Schema Objects Lecture 3: Creating Other Schema Objects ORACLE.
12 Copyright © Oracle Corporation, All rights reserved. Other Database Objects.
Other database objects (Sequence). What Is a Sequence? A sequence: Automatically generates sequential numbers Is a sharable object Is typically used to.
11 Copyright © 2007, Oracle. All rights reserved. Creating Other Schema Objects.
Chapter 6 Additional Database Objects Oracle 10g: SQL.
1 Copyright © 2004, Oracle. All rights reserved. Introduction.
1 Database Administration. 2 Objectives  Understand, create, and drop views  Grant and revoke users’ privileges  Understand and obtain information.
Chapter 6 Database Administration
Lecture 2: Using DDL Statements to Create and Manage Tables & Indexes
10 Creating and Managing Tables Objectives At the end of this lesson, you will be able to: Describe the main database objects Create tables Describe.
Database Programming Sections 11 & 12 – Creating, and Managing Views, Sequences, Indexes, and Synonymns.
Copyright  Oracle Corporation, All rights reserved. 10 Creating and Managing Tables.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
11-1 Copyright  Oracle Corporation, All rights reserved. What Are Constraints? Constraints enforce rules at the table level. Constraints prevent.
SQL: Part 1 Original materials supplied by the Oracle Academic Initiative (OAI). Edited for classroom use by Professor Laku Chidambaram. Not for commercial.
Database Programming Sections 11 & 12 –Sequences, Indexes, and Synonymns.
1 DBS201: More on SQL Lecture 3. 2 Agenda How to use SQL to update table definitions How to update data in a table How to join tables together.
© 2009 Punjab University College of Information Technology (PUCIT) September 8, 2009 Slide 1 (SQL) Other Database Objects Asif Sohail University of the.
Chapter 4 Indexes. Indexes Logically represents subsets of data from one or more tables View Generates numeric valuesSequence Basic unit of storage; composed.
Chapter 12 Additional Database Objects. Chapter Objectives  Define the purpose of a sequence and state how it can be used by an organization  Explain.
Altering Tables and Constraints Database Systems Objectives Add and modify columns. Add, enable, disable, or remove constraints. Drop a table. Remove.
Creating Indexes on Tables An index provides quick access to data in a table, based on the values in specified columns. A table can have more than one.
Database Security. Multi-user database systems like Oracle include security to control how the database is accessed and used for example security Mechanisms:
Database Programming Sections 12 – Sequences, Indexes, and Synonymns.
Chapter 12Introduction to Oracle9i: SQL1 Chapter 12 Additional Database Objects.
Chapter Fourteen INDEX and SYNONYM Dr. Chitsaz Objectives: Create and maintain Indexes Types and applications of Indexes Create Synonym Application of.
 CONACT UC:  Magnific training   
8 Copyright © 2005, Oracle. All rights reserved. Managing Schema Objects.
1 Chapters 19 and 20  Ch. 19: By What Authority? Users Roles Grant and revoke Synonyms  Ch. 20: Changing the Oracle Surroundings Indexes Clusters Sequences.
Controlling User Access
Controlling User Access
Controlling User Access
Objectives User access Create users Create roles
TABLES AND INDEXES Ashima Wadhwa.
Controlling User Access
Indexes By Adrienne Watt.
Database Security.
Oracle Certified 1z0-047 Exam Questions
Creating Other Schema Objects
Database Security.
Other Database Objects
Lecturer: Mukhtar Mohamed Ali “Hakaale”
Creating Other Schema Objects
Chapter 8 Working with Databases and MySQL
Chapter 5 Sequences.
Managing Objects with Data Dictionary Views
Managing Schema Objects
Chapter 4 Indexes.
CH 4 Indexes.
Chapter 2 Views.
Managing Objects with Data Dictionary Views
A Guide to SQL, Eighth Edition
CH 4 Indexes.
Chapter 2 Views.
Contents Preface I Introduction Lesson Objectives I-2
IST 318 Database Administration
Other Database Objects
Presentation transcript:

Creating Indexes

15-2 Database Systems Objectives Distinguish between the indexes that are created automatically and those that are created manually. Identify the uses for indexes. Explain the index structure and why it improves query speed. Create a non-unique index. Remove an index from the data dictionary. Evaluate guidelines for creating and using indexes.

15-3 Database Systems What Is an Index? Database object Used by the Oracle Server to speed up the retrieval of rows by using a pointer Reduces disk I/O by using rapid path access method to locate the data quickly Independent of the table it indexes Automatically used and maintained by the Oracle Server

15-4 Database Systems 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 non-unique indexes on columns to speed up access time to the rows.

15-5 Database Systems Create an index on one or more columns. Example Improve the speed of query access on the ENAME column in the EMP table. Creating an Index: Syntax CREATE INDEX index ON table (column[, column]...); CREATE INDEX index ON table (column[, column]...); SQL> CREATE INDEX emp_ename_idx 2 ON emp(ename); 2 ON emp(ename); Index created. SQL> CREATE INDEX emp_ename_idx 2 ON emp(ename); 2 ON emp(ename); Index created.

15-6 Database Systems 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. More indexes do not always speed up queries.

15-7 Database Systems When Not to Create an Index Do not create an index if 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.

15-8 Database Systems 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> SELECTic.index_name, ic.column_name, 2 ic.column_position col_pos,ix.uniqueness 2 ic.column_position col_pos,ix.uniqueness 3 FROMuser_indexes ix, user_ind_columns ic 3 FROMuser_indexes ix, user_ind_columns ic 4 WHEREic.index_name = ix.index_name 4 WHEREic.index_name = ix.index_name 5 ANDic.table_name = 'EMP'; 5 ANDic.table_name = 'EMP'; SQL> SELECTic.index_name, ic.column_name, 2 ic.column_position col_pos,ix.uniqueness 2 ic.column_position col_pos,ix.uniqueness 3 FROMuser_indexes ix, user_ind_columns ic 3 FROMuser_indexes ix, user_ind_columns ic 4 WHEREic.index_name = ix.index_name 4 WHEREic.index_name = ix.index_name 5 ANDic.table_name = 'EMP'; 5 ANDic.table_name = 'EMP';

15-9 Database Systems Removing an Index Remove an 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 emp_ename_idx; Index dropped.

15-10 Database Systems Summary Indexes are database objects that are used to improve query retrieval speed. Some unique indexes are created automatically. Users can create indexes by issuing the CREATE INDEX command. The definition of the index is in the USER_INDEXES data dictionary table.

15-11 Database Systems Practice Overview Creating non-unique indexes Displaying data dictionary information about the index Dropping indexes

15-12 Database Systems Practice 1 Create a sequence to be used with the primary key column of the DEPARTMENT table. The sequence should start at 60 and have a maximum value of 200. Have your sequence increment by ten numbers. Name the sequence DEPT_ID_SEQ. Write a script to display the following information about your sequence: sequence name, maximum value, increment size, and last number. Execute your script.

15-13 Database Systems Practice 2 Write an interactive script to insert a row into the DEPARTMENT table. Be sure to use the sequence you created for the ID column. Create a customized prompt to enter the department name. Execute the script and add two departments named Education and Administration. Confirm your additions.

15-14 Database Systems Practice 3 Create a non-unique index on the foreign key column in the EMPLOYEE table. Display the indexes and uniqueness that exist in the data dictionary for the EMPLOYEE table.