Chapter 6 Additional Database Objects

Slides:



Advertisements
Similar presentations
9 Creating and Managing Tables. Objectives After completing this lesson, you should be able to do the following: Describe the main database objects Create.
Advertisements

Chapter Thirteen Sequences Dr. Chitsaz Objectives: Sequence objects Create and use sequences Application of sequences.
Copyright  Oracle Corporation, All rights reserved. 10 Creating and Managing Tables.
11-1 Copyright © Oracle Corporation, All rights reserved. Different type of keys.
Database Programming Sections 13. Marge Hohly  1. Which statements are True about the following sequence? The sequence was used to generate numbers.
10 Copyright © 2004, Oracle. All rights reserved. Creating Other Schema Objects.
Introduction to Structured Query Language (SQL)
A Guide to Oracle9i1 Advanced SQL And PL/SQL Topics Chapter 9.
Copyright س Oracle Corporation, All rights reserved. 13 Other Database Objects.
Introduction to Structured Query Language (SQL)
Chapter 5 Data Manipulation and Transaction Control Oracle 10g: SQL
Using SQL Queries to Insert, Update, Delete, and View Data © Abdou Illia MIS Spring 2015 Wednesday 1/28/2015 Chapter 3A.
SQL's Data Definition Language (DDL) – View, Sequence, Index.
13 Other Database Objects Important Legal Notice:  Materials on this lecture are from a book titled “Oracle Education” by Kochhar, Gravina, and Nathan.
Objectives After completing this lesson, you should be able to do the following: Categorize the main database objects Review the table structure List.
Dr. Chen, Oracle Database System (Oracle) 1 Chapter 6 Additional Database Objects (up to p.195 and all in the pptx file) Jason C. H. Chen, Ph.D. Professor.
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.
Set operators The set operaotrs combine the result of two or more component queries into one result. queries containing set operators are called compound.
Chapter 6 Additional Database Objects Oracle 10g: SQL.
Chapter 5 Sequences.
10 Copyright © 2009, Oracle. All rights reserved. Using DDL Statements to Create and Manage Tables.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
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.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Database Programming Sections 11 & 12 – Creating, and Managing Views, Sequences, Indexes, and Synonymns.
9 Copyright © Oracle Corporation, All rights reserved. Creating and Managing Tables.
Copyright  Oracle Corporation, All rights reserved. 10 Creating and Managing Tables.
ITBIS373 Database Development Lecture 3a - Chapter 3: Using SQL Queries to Insert, Update, Delete, and View Data.
CHAPTER 9 Views, Synonyms, and Sequences. Views are used extensively in reporting applications and also to present subsets of data to applications. Synonyms.
Oracle 11g: SQL Chapter 4 Constraints.
Chapter 4 Constraints Oracle 10g: SQL. Oracle 10g: SQL 2 Objectives Explain the purpose of constraints in a table Distinguish among PRIMARY KEY, FOREIGN.
Database Programming Sections 11 & 12 –Sequences, Indexes, and Synonymns.
George Mpopo | Rosebank College ADVANCED DATABASES WITH ORACLE 11g FOR ADDB7311 LEARNING UNIT 2 of 7.
© 2009 Punjab University College of Information Technology (PUCIT) September 8, 2009 Slide 1 (SQL) Other Database Objects Asif Sohail University of the.
9 Copyright © Oracle Corporation, All rights reserved. Creating and Managing Tables.
Chapter 13 Views Oracle 10g: SQL. Oracle 10g: SQL2 Objectives Create a view, using CREATE VIEW command or the CREATE OR REPLACE VIEW command Employ the.
Chapter 5 : Integrity And Security  Domain Constraints  Referential Integrity  Security  Triggers  Authorization  Authorization in SQL  Views 
Session 1 Module 1: Introduction to Data Integrity
Chapter 4 Indexes. Indexes Logically represents subsets of data from one or more tables View Generates numeric valuesSequence Basic unit of storage; composed.
Transactions, Roles & Privileges Oracle and ANSI Standard SQL Lecture 11.
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.
DDL and Views. Database Objects Logically represents subsets of data from one or more tables View Generates numeric valuesSequence Basic unit of storage;
A Guide to SQL, Eighth Edition Chapter Six Updating Data.
Indexes- What?  Optional structures associated with tables  Provides a quick access path to table data  You can create indexes on one or more columns.
Creating and Managing Tables 14. ObjectivesObjectives After completing this lesson, you should be able to do the following: After completing this lesson,
Database Programming Sections 12 – Sequences, Indexes, and Synonymns.
Chapter 12Introduction to Oracle9i: SQL1 Chapter 12 Additional Database Objects.
Chapter 3 Table Creation and Management Oracle 10g: SQL.
1 11g NEW FEATURES ByVIJAY. 2 AGENDA  RESULT CACHE  INVISIBLE INDEXES  READ ONLY TABLES  DDL WAIT OPTION  ADDING COLUMN TO A TABLE WITH DEFAULT VALUE.
 CONACT UC:  Magnific training   
Oracle 11g: SQL Chapter 5 Data Manipulation and Transaction Control.
Creating Indexes Database Systems Objectives Distinguish between the indexes that are created automatically and those that are created manually.
Other database objects (Sequence and view). What Is a Sequence? A sequence: Automatically generates sequential numbers Is a sharable object Is typically.
ITEC 313 Database Programming
Oracle Certified 1z0-047 Exam Questions
Creating Other Schema Objects
Other Database Objects
Creating Other Schema Objects
Chapter 5 Sequences.
Managing Objects with Data Dictionary Views
Chapter 4 Indexes.
CH 4 Indexes.
CH 4 Indexes.
Contents Preface I Introduction Lesson Objectives I-2
IST 318 Database Administration
Other Database Objects
Presentation transcript:

Chapter 6 Additional Database Objects Oracle 11g: SQL Chapter 6 Additional Database Objects

Objectives Define the purpose of a sequence and state how it can be used in a database Explain why gaps may appear in the integers generated by a sequence Use the CREATE SEQUENCE command to create a sequence Call and use sequence values Identify which options cannot be changed by the ALTER SEQUENCE command Delete a sequence Oracle 11g: SQL 2

Objectives (continued) Create indexes with the CREATE INDEX command Explain the main index structures: B-tree and bitmap Verify index use with the explain plan Introduce variations on conventional indexes, including a function-based index and an index organized table Oracle 11g: SQL 3

Objectives (continued) Verify index existence via the data dictionary Rename an index with the ALTER INDEX command Remove an index using the DELETE INDEX command Create and remove a public synonym Oracle 11g: SQL 4

Database Objects An object is anything that has a name and defined structure Includes: Table – stores data Sequence – generates sequential integers Index – allows users to quickly locate specific records Synonym – alias for other database objects Oracle 11g: SQL 5

Sequences Used for internal control purposes by providing sequential integers for auditing Used to generate unique value for primary key column Surrogate key = no correlation with actual row contents Oracle 11g: SQL 6

Creating a Sequence Use the CREATE SEQUENCE command Various intervals are allowed – Default: 1 You can specify the starting number – Default: 1 Oracle 11g: SQL

Creating a Sequence (continued) Can specify MINVALUE for decreasing sequence and MAXVALUE for increasing sequence Numbers can be reused if CYCLE is specified ORDER clause is used in application cluster environment Use CACHE to pregenerate integers – Default: 20 Oracle 11g: SQL 8

Creating a Sequence (continued) Oracle 11g: SQL 9

Creating a Sequence (continued) To verify the settings for options of a sequence, query USER_SEQUENCES data dictionary view Next Number to issue Oracle 11g: SQL

Using Sequence Values NEXTVAL – generates integer Oracle 11g: SQL

Using Sequence Values (continued) CURRVAL – contains last integer generated by NEXTVAL Oracle 11g: SQL

Altering Sequence Definitions Use ALTER SEQUENCE command to change the settings for a sequence START WITH value cannot be altered – drop the sequence and re-create it Changes cannot make current integers invalid Oracle 11g: SQL 13

ALTER SEQUENCE Command Example Oracle 11g: SQL 14

Removing a Sequence Use the DROP SEQUENCE command to delete a sequence Previous values generated are not affected by removing a sequence from a database Oracle 11g: SQL

Removing a Sequence (continued) Oracle 11g: SQL

Indexes An index stores frequently referenced values and ROWIDs Can be based on one column, multiple columns, functions, or expressions Oracle 11g: SQL 17

B-Tree Index Oracle 11g: SQL 18

B-Tree Index (continued) Implicitly create an index by PRIMARY KEY and UNIQUE constraints Explicitly create an index by using the CREATE INDEX command Oracle 11g: SQL 19

CREATE INDEX Command Examples Oracle 11g: SQL 20

The Explain Plan Oracle 11g: SQL 21

Bitmap Indexes Oracle 11g: SQL 22

Function-Based Indexes Oracle 11g: SQL 23

Index Organized Tables An IOT stores table contents in a B-tree index structure Use the “ORGANIZATION INDEX” option in a CREATE TABLE statement to build an IOT Oracle 11g: SQL

Verifying an Index Use the USER_INDEXES data dictionary view to determine that the index exists Use the USER_IND_COLUMNS data dictionary view to determine the column index information Oracle 11g: SQL

Verifying an Index (continued) Oracle 11g: SQL

USER_IND_COLUMNS Oracle 11g: SQL 27

Removing an Index Use the DROP INDEX command to remove an index Oracle 11g: SQL

Synonyms Synonyms serve as permanent aliases for database objects Simplify object references Can be private or public Private synonyms are only available to the user who created them PUBLIC synonyms are available to all database users Oracle 11g: SQL 29

CREATE SYNONYM Command Syntax Oracle 11g: SQL 30

CREATE SYNONYM Command Oracle 11g: SQL 31

Deleting a SYNONYM A private synonym can be deleted by its owner A PUBLIC synonym can only be deleted by a user with DBA privileges Oracle 11g: SQL

Summary A sequence can be created to generate a series of integers The values generated by a sequence can be stored in any table A sequence is created with the CREATE SEQUENCE command Gaps in sequences might occur if the values are stored in various tables, if numbers are cached but not used, or if a rollback occurs A value is generated by using the NEXTVAL pseudocolumn The CURRVAL pseudocolumn is NULL until a value is generated by NEXTVAL The USER_OBJECTS data dictionary object can be used to confirm the existence of all schema objects The USER_SEQUENCES data dictionary object is used to view sequence settings Oracle 11g: SQL 33

Summary (continued) The ALTER SEQUENCE command is used to modify an existing sequence; the only settings that can’t be modified are the START WITH option and any option that would be invalid because of previously generated values The DUAL table is helpful for testing sequence value generation The DROP SEQUENCE command deletes an existing sequence An index can be created to speed up the query process DML operations are always slower when indexes exist Oracle 11g creates an index for PRIMARY KEY and UNIQUE constraints automatically An explicit index is created with the CREATE INDEX command An index can be used by Oracle 11g automatically if a query criterion or sort operation is based on a column or an expression used to create the index Oracle 11g: SQL 34

Summary (continued) The two main structures for indexes are B-tree and bitmap The explain plan can verify whether an index is used in a query Function-based indexes are used to index an expression or the use of functions on a column or columns An index organized table is a table stored in a B-tree structure to combine the index and table into one database object Information about an index can be retrieved from the USER_INDEXES and USER_IND_COLUMNS views An index can be dropped with the DROP INDEX command An index can be renamed with the ALTER INDEX command Oracle 11g: SQL 35

Summary (continued) Except for a name change, an index can’t be modified; it must be deleted and then re-created A synonym provides a permanent alias for a database object A public synonym is available to any database user A private synonym is available only to the user who created it A synonym is created by using the CREATE SYNONYM command A synonym is deleted by using the DROP SYNONYM command Only a user with DBA privileges can drop a public synonym Oracle 11g: SQL