13 Other Database Objects Important Legal Notice:  Materials on this lecture are from a book titled “Oracle Education” by Kochhar, Gravina, and Nathan.

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.
Managing Objects with Data Dictionary Views
Database Programming Sections 13. Marge Hohly  1. Which statements are True about the following sequence? The sequence was used to generate numbers.
7 7 Multiple-Column Subqueries Important Legal Notice:  Materials on this lecture are from a book titled “Oracle Education” by Kochhar, Gravina, and Nathan.
10 Copyright © 2004, Oracle. All rights reserved. Creating Other Schema Objects.
Copyright س Oracle Corporation, All rights reserved. 13 Other Database Objects.
SQL's Data Definition Language (DDL) – View, Sequence, Index.
Chapter 6 Additional Database Objects
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.
Displaying Data from Multiple Tables (Join) Displaying Data from Multiple Tables (Join) Displaying Data from Multiple Tables (Join Displaying Data from.
Chapter 5 Sequences.
10 Copyright © 2009, Oracle. All rights reserved. Using DDL Statements to Create and Manage Tables.
1 Copyright © 2006, Oracle. All rights reserved. Using DDL Statements to Create and Manage Tables.
Controlling User Access. Objectives After completing this lesson, you should be able to do the following: Create users Create roles to ease setup and.
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.
9 Copyright © Oracle Corporation, All rights reserved. Creating and Managing Tables.
Copyright  Oracle Corporation, All rights reserved. 10 Creating and Managing Tables.
Chapter 3 Selected Single-Row Functions and Advanced DML & DDL.
CHAPTER 9 Views, Synonyms, and Sequences. Views are used extensively in reporting applications and also to present subsets of data to applications. Synonyms.
4 Displaying Data from Multiple Tables Important Legal Notice:  Materials on this lecture are from a book titled “Oracle Education” by Kochhar, Gravina,
11-1 Copyright  Oracle Corporation, All rights reserved. What Are Constraints? Constraints enforce rules at the table level. Constraints prevent.
Copyright  Oracle Corporation, All rights reserved. 11 Including Constraints.
Copyright  Oracle Corporation, All rights reserved. Introduction.
11 Including Constraints Objectives At the end of this lesson, you will be able to: Describe constraints Create and maintain constraints At the.
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 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.
DDL and Views. Database Objects Logically represents subsets of data from one or more tables View Generates numeric valuesSequence Basic unit of storage;
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.
 CONACT UC:  Magnific training   
Displaying Data from Multiple Tables (Join) Displaying Data from Multiple Tables (Join) Displaying Data from Multiple Tables (Join Displaying Data from.
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.
Controlling User Access
Controlling User Access
Including Constraints
Oracle Certified 1z0-047 Exam Questions
Creating Other Schema Objects
Other Database Objects
15 SQL Workshop Important Legal Notice:
Creating Other Schema Objects
Chapter 5 Sequences.
Managing Objects with Data Dictionary Views
Ch 3 Synonym.
Ch 3 Synonym.
Chapter 4 Indexes.
CH 4 Indexes.
Database Programming Sections 11-12–Sequences, Indexes & Synonyms, Controlling User Access, Creating & Revoking Object Privileges 11/25/08.
CH 4 Indexes.
Ch 3 Synonym.
Contents Preface I Introduction Lesson Objectives I-2
Chapter 3 Synonym.
Other Database Objects
Presentation transcript:

13 Other Database Objects Important Legal Notice:  Materials on this lecture are from a book titled “Oracle Education” by Kochhar, Gravina, and Nathan (1999), published by Oracle Corp.  For further information, visit  This presentation must be used for only education purpose for students at Central Washington University which is a member of Oracle Academic Initiatives (OAI) and has used Oracle systems for HRIS & Accounting Systems as a database platform for its PeopleSoft ERP system, since 1999.

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

Database Objects

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

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}];

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 2INCREMENT BY 1 3START WITH 91 4MAXVALUE 100 5NOCACHE 6NOCYCLE; Sequence created.

Confirming Sequences Verify your sequence values in the USER_SEQUENCES data dictionary table. The LAST_NUMBER column displays the next available sequence number. SQL> SELECTsequence_name, min_value, max_value 2increment_by, last_number 3 FROMuser_sequences;

NEXVAL 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.

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.

Using a Sequence Insert a new department named “MARKETING” in San Diego. View the current value for the DEPT_DEPTNO sequence. SQL> INSERT INTOdept(deptno, dname, loc) 2 VALUES(dept_deptno.NEXTVAL, 3 FROM‘MARKETING’, ‘SAN DIEGO’); 1 row created. SQL> SELECT dept(deptno, dname, loc) 2 FROM dual;

Using a Sequence Caching sequences 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.

Modifying a Sequence Change the increment value, maximum value, minimum value, cycle option, or cache option. SQL> CREATE SEQUENCE dept_deptno 2INCREMENT BY 1 3MAXVALUE NOCACHE 5NOCYCLE; Sequence altered.

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.

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 deptno_deptno; Sequence dropped.

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

Creating an Index Create an index on one or more columns. Improve the speed of query access on the ENAME column in the EMP table. CREATE INDEXindex ON table (column[, column]…); SQL> CREATE INDEXemp_ename_idx 2 ONemp(ename); Index created.

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.

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.

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, 2ic.column_position col_pos, ix.uniqueness 3FROMuser_indexes it, user_ind_columns ic 4WHEREic.index_name = ix.index_name 5ANDic.table_name = ‘EMP’;

Function-Based Indexes A function-based index is an index based on expressions. The index expression is built from table columns, constants, SQL functions, and user-defined functions. SQL>CREATE TABLE test (col1 NUMBER); SQL> CREATE INDEX test_index on test (col1, col1+10); SQL>SELECT col1+10 FROM test;

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 index; SQL> DROP INDEX emp_ename_idx; Index dropped.

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;

Creating and Removing Synonyms Create a shortened name for the DEPT_SUM_VU view. Drop a synonym. SQL> CREATE SYNONYM d_sum 2FOR dept_sum_vu; Synonym created. SQL> DROP SYNONYM d_sum; Synonym dropped.

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.

Practice Overview Creating sequences Using sequences Creating nonunique indexes Displaying data dictionary information about sequences and indexes Dropping indexes