Chapter Thirteen Sequences Dr. Chitsaz Objectives: Sequence objects Create and use sequences Application of sequences.

Slides:



Advertisements
Similar presentations
SQL/PL SQL Oracle By Rana Umer. Performance Tuning Indexes ROWID View Sequences Oracle By Rana Umer.
Advertisements

9 Creating and Managing Tables. Objectives After completing this lesson, you should be able to do the following: Describe the main database objects Create.
Data Definition Language (DDL)
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.
Sequence Sen Zhang. The AutoNumber data type stores an integer that Access increments (adds to) automatically as you add new records. You can use the.
Chapter 3: Using SQL Queries to Insert, Update, Delete, and View Data
Copyright س Oracle Corporation, All rights reserved. 13 Other Database Objects.
Using SQL Queries to Insert, Update, Delete, and View Data © Abdou Illia MIS Spring 2015 Wednesday 1/28/2015 Chapter 3A.
SQL: Interactive Queries (2) Prof. Weining Zhang.
SQL's Data Definition Language (DDL) – View, Sequence, Index.
Chapter 9 Other Database Objects. Creating and Managing Sequences An Oracle sequence is a named sequential number generator. Sequences are often used.
Chapter 6 Additional Database Objects
WHAT SEQUENCE OBJECTS ARE (AND ARE NOT) Louis Davidson Data Architect.
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.
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.
Oracle Database Administration
12 Copyright © Oracle Corporation, All rights reserved. Other Database Objects.
Oracle’s take on joins Where it differs from ANSI standard.
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.
Oracle Sequences Sequences are an independent object in the database (not a data type) Sequences have a name and can be used anywhere a value is expected.
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.
WHAT SEQUENCE OBJECTS ARE (and are not) Presentation by Louis Davidson
Database Programming Sections 11 & 12 – Creating, and Managing Views, Sequences, Indexes, and Synonymns.
ITBIS373 Database Development Lecture 3a - Chapter 3: Using SQL Queries to Insert, Update, Delete, and View Data.
Chapter 3 Selected Single-Row Functions and Advanced DML & DDL.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
CHAPTER 9 Views, Synonyms, and Sequences. Views are used extensively in reporting applications and also to present subsets of data to applications. Synonyms.
SQL: Advanced topics Prof. Weining Zhang Cs.utsa.edu.
SQL1-ch10 其他綱要物件. 題號  80 題: 5 、 9 、 18 、 32 、 38 、 41 、 44 、 54 、 77  140 題: 76 、 78 、 120 、 132.
Database Programming Sections 11 & 12 –Sequences, Indexes, and Synonymns.
5. Simple SQL using Oracle1 Simple SQL using Oracle 5. Working with Tables: Data management and Retrieval 6. Working with Tables: Functions and Grouping.
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.
SQL ACTION QUERIES AND TRANSACTION CONTROL CS 260 Database Systems.
A SParqly Jython++ A SParqly Jython++ an ASP/SPARQL enhanced Jython Cliff Cheng Carlos Urrutia Francisco Garcia.
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.
DDL and Views. Database Objects Logically represents subsets of data from one or more tables View Generates numeric valuesSequence Basic unit of storage;
Database Programming Sections 12 – Sequences, Indexes, and Synonymns.
Chapter 12Introduction to Oracle9i: SQL1 Chapter 12 Additional Database Objects.
Sequences Sequences: a database object that generates unique numbers from an arithmetic series. Used to populated surrogate keys. Syntax: CREATE SEQUENCE.
Chapter 8 Advanced SQL. Relational Set Operators UNIONINTERSECTMINUS Work properly if relations are union- compatible –Names of relation attributes must.
Displaying Data from Multiple Tables (Join) Displaying Data from Multiple Tables (Join) Displaying Data from Multiple Tables (Join Displaying Data from.
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.
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
CH3 Part2 Displaying Data from Multiple Tables (Join) Sub queries
Chapter 5 Sequences.
Managing Objects with Data Dictionary Views
The Basics of Data Manipulation
Chapter 4 Indexes.
Database Programming Sections 11-12–Sequences, Indexes & Synonyms, Controlling User Access, Creating & Revoking Object Privileges 11/25/08.
თანამედროვე მონაცემთა ბაზების მართვის სისტემები
Contents Preface I Introduction Lesson Objectives I-2
Other Database Objects
Presentation transcript:

Chapter Thirteen Sequences Dr. Chitsaz Objectives: Sequence objects Create and use sequences Application of sequences

2 Objects Object Types: –Table –View –Sequence –Index –Synonym

3 SEQUENCE Automatically generates sequence number (For rows in tables) Is sharable among tables. Typically used to create a primary key value (Unique numbers and may have gaps) Stored and generated independently of tables. So the same sequence may be used in several tables.

4 CREATE SEQUENCE: CREATE SEQUENCEsequence [INCREMENT BY n] --negative number to decrement [START With n] [MAXVALUE n| NOMAXVALUE ] [MINVALUE n| NOMINVALUE ] [CYCLE | NOCYCLE ] --start over or not [CACHE n | NOCACHE ]; --n numbers stored in memory for efficiency; default is 20;

5 CREATE SEQUENCE: Example: CREATE SEQUENCE id_seq INCREMENT BY 1 START WITH 1000 MAXVALUE NOCACHE NOCYCLE ;

6 CONFIRMING SEQUENCE: Since it is an object, it can be query: SELECT sequence_name, min_value, max_value, increment_by, last_number --next number stored FROMuser_sequences; -- or use SEQ

7 CONFIRMING SEQUENCE: NEXTVAL: --next available sequence number CURRVAL: --present value NEXTVAL & CURRVAL can not be used in: SELECT list of a view SELECT with distinct clause SELECT with group by SELECT having SELECT order by SELECT union/intersect/minus Subquery in SELECT, INSERT, or UPDATE

8 USING A SEQUENCE: INSERT INTO student (id, name) VALUES(id_seq.NEXTVAL, '&name'); View the current value of the sequence id_seq: SELECTid_seq.CURRVAL FROMdual;

9 USING A SEQUENCE: SELECT id_seq.CURRVAL, id_seq.NEXTVAL FROM dual; --if currval and nextval is used in the same query, both return the same number.

10 USING A SEQUENCE: INSERT INTO student_course (Id, C_num, Dept_name) VALUES(Stud_Seq.NEXTVAL, Course_Seq.NEXTVAL, ’&Dept_name’);

11 Gaps in sequence values: it is possible to have gaps in the sequence: A rollback The system crashes A sequence is used in another table

12 Modifying a sequence: ALTER SEQUENCE id_seq INCREMENT BY 10 START WITH 1000 MAXVALUE NOCACHE NOCYCLE;

13 Rules for Modifying a Sequence: You must be the owner or have the ALTER privilege Only future sequence numbers are affected To restart a sequence, the sequence must be dropped and recreated.

14 Dropping a Sequence: DROP SEQUENCE id_seq;

15 Question? id_seq is 150; We would like to change the lastvalue to 350.