2/1/04Database Systems: Salman Azhar1 Object-Relational Databases Salman Azhar User-Defined Types Object IDs Nested Tables These slides use some figures,

Slides:



Advertisements
Similar presentations
Oracle Object-Relational Model. - Structures : tables, views, indexes, etc. - Operations : actions that manipulate data stored in structures - Integrity.
Advertisements

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
BD05/06 PL/SQL  Introduction  Structure of a block  Variables and types  Accessing the database  Control flow  Cursors  Exceptions  Procedures.
1 More SQL Database Modification Defining a Database Schema Views.
AN INTRODUCTION TO PL/SQL Mehdi Azarmi 1. Introduction PL/SQL is Oracle's procedural language extension to SQL, the non-procedural relational database.
PL/SQL. Introduction to PL/SQL PL/SQL is the procedure extension to Oracle SQL. It is used to access an Oracle database from various environments (e.g.
SQL Group Members: Shijun Shen Xia Tang Sixin Qiang.
CSC 570 Notes for Chapter 10 Advanced Topics in Relational Databases.
1 Object-Relational Databases User-Defined Types Object ID’s Nested Tables.
1 Introduction to SQL Multirelation Queries Subqueries Slides are reused by the approval of Jeffrey Ullman’s.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
1 More SQL Database Modification Defining a Database Schema Views Source: slides by Jeffrey Ullman.
Constraints and Triggers Foreign Keys Local and Global Constraints Triggers.
1 Constraints Foreign Keys Local and Global Constraints Triggers Source: slides by Jeffrey Ullman.
Winter 2002Arthur Keller – CS 18012–1 Schedule Today: Feb. 19 (T) u Object-Relational Systems. u Read Sections 4.5, Assignment 5 due. Feb. 21.
1 More SQL Defining a Database Schema Views. 2 Defining a Database Schema uA database schema comprises declarations for the relations (“tables”) of the.
1 SQL Authorization Privileges Grant and Revoke Grant Diagrams.
1 Constraints Foreign Keys Local and Global Constraints Triggers.
1 SQL Authorization Privileges Grant and Revoke Grant Diagrams.
1 Constraints Foreign Keys Local and Global Constraints Triggers.
Fall 2001Arthur Keller – CS 18014–1 Schedule Nov. 13 (T) Object-Relational, O-R Queries. u Read Sections 4.5, Assignment 6 due. (No office hours.)
Winter 2002Judy Cushing12–1 Schedule Today (week 8): u Object-Relational Systems. Sections 4.5, u Assignment 5 debriefed. u Transactions, Authorization.
Creating Tables, Defining Constraints Rose-Hulman Institute of Technology Curt Clifton.
1 SQL/PSM Procedures Stored in the Database General-Purpose Programming.
1 PL/SQL Oracle’s Version of Triggers and PSM. 2 PL/SQL uOracle uses a variant of SQL/PSM which it calls PL/SQL. uPL/SQL not only allows you to create.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 11 Object and Object- Relational Databases.
McGraw-Hill/Irwin Copyright © 2007 by The McGraw-Hill Companies, Inc. All rights reserved. Chapter 18 Object Database Management Systems.
Main challenges in XML/Relational mapping Juha Sallinen Hannes Tolvanen.
Object and object-relational databases 1. Object databases vs. Object-relational databases Object databases Stores complex objects – Data + functions.
Database System Concepts and Architecture Lecture # 3 22 June 2012 National University of Computer and Emerging Sciences.
Bordoloi and Bock CURSORS. Bordoloi and Bock CURSOR MANIPULATION To process an SQL statement, ORACLE needs to create an area of memory known as the context.
PL / SQL P rocedural L anguage / S tructured Q uery L anguage Chapter 7 in Lab Reference.
ORDBS1 Object Relational Database Systems: 1. Introduction 2. Objects in SQL3 3. Comparison of ODL/OQL and SQL3 Approaches CIS 671.
1 Advanced Databases (CM036): Lecture # 5 ( Object-Relational and Nested-Relational Databases) Introduction to Object-Relational features of Oracle 9i.
1 Object-Relational Databases User-Defined Types Nested Tables.
Constraints on Relations Foreign Keys Local and Global Constraints Triggers Following lecture slides are modified from Jeff Ullman’s slides
Winter 2006Keller, Ullman, Cushing9–1 Constraints Commercial relational systems allow much more “fine-tuning” of constraints than do the modeling languages.
RELATIONAL DATA MODEL 1. 2 What is a Data Model? 1.Mathematical representation of data. wExamples: relational model = tables; semistructured model = trees/graphs.
Winter 2006Keller, Ullman, Cushing12–1 Object-Relational Systems Object-oriented ideas enter the relational world. u Keep relation as the fundamental abstraction.
Chapter 18 Object Database Management Systems. McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Outline Motivation for object.
Lecture2: Database Environment Prepared by L. Nouf Almujally 1 Ref. Chapter2 Lecture2.
Object-Relational SQL CIS 4301 Lecture Notes 4/20/2006.
1 Object-Relational Databases User-Defined Types Object ID’s Nested Tables.
1 Real SQL Programming Persistent Stored Modules (PSM) PL/SQL Embedded SQL.
BIS Database Systems School of Management, Business Information Systems, Assumption University A.Thanop Somprasong Chapter # 8 Advanced SQL.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
1 More SQL uDatabase Modification uDefining a Database Schema uViews.
Copyright © 2004 Pearson Education, Inc.. Chapter 22 Object-Relational and Extended-Relational Systems.
Chapter 2 Object-Relational DBMSs Chapter 28 in Textbook.
Object Relational Features
Chapter 9: Advanced SQL and PL/SQL Guide to Oracle 10g.
CSCE 520- Relational Data Model Lecture 2. Oracle login Login from the linux lab or ssh to one of the linux servers using your cse username and password.
FEN NOEA/IT - Databases/ORDB1 Object-Relational Databases The Evolutionary Approach to Closing the Gap between Relational Tables and Object Models.
Object-Relational Model. Review: Data Models Hierarchical Network ER (Pure) Relational (Pure) Object-oriented (ODMG) Object-relational (since SQL:1999)
Chapter 18 Object Database Management Systems. Outline Motivation for object database management Object-oriented principles Architectures for object database.
Databases : SQL-Schema Definition and View 2007, Fall Pusan National University Ki-Joune Li These slides are made from the materials that Prof. Jeffrey.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 8 Object-Relational Database.
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Chapter 12 Outline Overview of Object Database Concepts Object-Relational Features Object Database.
CS422 Principles of Database Systems Object-Oriented Features in DBMS Chengyu Sun California State University, Los Angeles.
1 Data Modification with SQL CREATE TABLE, INSERT, DELETE, UPDATE Slides from
1 Lecture 11 PL/SQL Slides from
Mapeo Objeto Relacional
CPSC-310 Database Systems
Object-Relational Databases
Object-Relational DBMSs
Object-Relational Systems
Object-Relational Databases
CMSC-461 Database Management Systems
Structured Types (9-12-2) Structured types allow composite attributes of E-R diagrams to be represented directly. Unnamed row types can also be used in.
Chapter 8 Advanced SQL.
Presentation transcript:

2/1/04Database Systems: Salman Azhar1 Object-Relational Databases Salman Azhar User-Defined Types Object IDs Nested Tables These slides use some figures, definitions, and explanations from Elmasri- Navathe’s Fundamentals of Database Systems and Molina-Ullman-Widom’s Database Systems

2/1/04Database Systems: Salman Azhar2 Merging Relational and Object Models uObject-oriented models support winteresting data types --- not just flat files. E.g., Maps, multimedia, etc. uThe relational model supports wvery-high-level queries uObject-relational databases are an attempt to get the best of both.

2/1/04Database Systems: Salman Azhar3 Evolution of DBMSs uObject-oriented DBMSs fell short wbecause they did not offer the efficiencies of a relational DBMS. uObject-relational extensions to relational DBMSs wcapture much of the advantages of OO wyet retain the relation as the fundamental abstraction.

2/1/04Database Systems: Salman Azhar4 SQL-99 and DBMS Features uSQL-99 includes many of the object- relational features to be described. uHowever, being so new, different DBMSs use different approaches. wWe’ll sometimes use features and syntax from Oracle and SQL Server.

2/1/04Database Systems: Salman Azhar5 User Defined Types uA user-defined type, or UDT, is essentially a class definition, with a structure and methods. uTwo uses: 1.As a row-type, that is, the type of a relation. 2.As an column-type, that is, the type if attribute in a relation.

2/1/04Database Systems: Salman Azhar6 UDT Definition CREATE TYPE AS ( ); uOracle syntax: 1.Add “OBJECT” as in CREATE TYPE AS OBJECT. 2.Follow with / to have the type stored.

2/1/04Database Systems: Salman Azhar7 Example: UDT Definition CREATE TYPE DealerType AS ( name CHAR(20), addrCHAR(20) ); CREATE TYPE CarType AS ( nameCHAR(20), manfCHAR(20) );

2/1/04Database Systems: Salman Azhar8 References uIf T is a type, then REF T is the type of a reference to T wthis means a pointer to an object of type T. woften called an “object ID” in OO systems. uUnlike object ID’s, a REF is visible, walthough it is usually gibberish.

2/1/04Database Systems: Salman Azhar9 Example: REF CREATE TYPE SellsType AS ( dealerREF DealerType, carREF CarType, priceFLOAT ); uSellsType objects look like: REF DealerType REF CarType FLOAT Reference to a DealerType object Reference to a CarType object

2/1/04Database Systems: Salman Azhar10 UDTs as Row Types uA table may be defined to have a schema that is a row type, rather than by listing its elements. uSyntax: wCREATE TABLE OF ; uCreates a table where each row is of

2/1/04Database Systems: Salman Azhar11 Example: Creating Tables CREATE TABLE Dealer OF DealerType; CREATE TABLE Car OF CarType; CREATE TABLE Sells OF SellsType;

2/1/04Database Systems: Salman Azhar12 Values of Relations with a Row-type uTechnically, a relation declared to have a rowtype DealerType (such as Dealer), wis not a set of pairs wit is a unary relation whose tuples are objects with two components: –name and addr.

2/1/04Database Systems: Salman Azhar13 Type Constructors uEach UDT has a type constructor of the same name that wraps objects of that type.

2/1/04Database Systems: Salman Azhar14 Example: Type Constructor uThe query SELECT * FROM Dealer; uProduces “tuples” such as: DealerType(‘AutoNation’, ‘Maple St.’)

2/1/04Database Systems: Salman Azhar15 Aliasing: Accessing Values From a Rowtype uIn Oracle and MS SQL Server, the dot works as expected wbut it may not work in all DBMS wso it is a good idea, to use an alias for every relation, when O-R features are used. uExample: SELECT dd.name, dd.addr FROM Dealer dd;

2/1/04Database Systems: Salman Azhar16 Accessing Values: SQL-99 Approach uIn SQL-99, each attribute of a UDT has: wGet method Called Generator methods (get the value) and wSet method Called Mutator methods (change the value) uThese methods have the same name as the attribute. wThe generator for A takes no argument, as A( ). wThe mutator for A takes a new value as argument, as A(v).

2/1/04Database Systems: Salman Azhar17 Example: SQL-99 Value Access uConsider SELECT dd.name, dd.addr FROM Dealer dd; uThe same query in SQL-99 is SELECT dd.name( ), dd.addr( ) FROM Dealer dd; Explicitly access generators

2/1/04Database Systems: Salman Azhar18 Inserting Row Type Values (Oracle Style) uWe can use a standard INSERT statement, wremembering that a relation with a row type is really unary and needs that type constructor. uExample: INSERT INTO Dealer VALUES( DealerType(‘AutoNation’, ‘Maple St.’) ); uNote: DealerType is a constructor

2/1/04Database Systems: Salman Azhar19 Inserting Values: SQL-99 Style 1.Create a variable X of the suitable type, using the constructor method for that type. 2.Use the mutator methods for the attributes to set the values of the fields of X. 3.Insert X into the relation.

2/1/04Database Systems: Salman Azhar20 Example: SQL-99 Insert uThe following must be part of a procedure, so we have a variable newDealer. SET newDealer = DealerType( ); newDealer.name(‘AutoNation’); newDealer.addr(‘Maple St.’); INSERT INTO Dealer VALUES(newDealer); Mutator methods change newDealer’s name and addr components. Construct a new dealer Insert new values

2/1/04Database Systems: Salman Azhar21 UDTs as Column Types uA UDT can be the type of a column (an attribute) win either another UDT definition wor in a CREATE TABLE statement uUse the name of the UDT as the type of the attribute

2/1/04Database Systems: Salman Azhar22 Example: Column Type CREATE TYPE AddrType AS ( streetCHAR(30), cityCHAR(20), zipINT ); CREATE TABLE Buyers ( nameCHAR(30), addrAddrType, favCarCarType ); Values of addr and favCar components are objects with 3 and 2 fields, respectively.

2/1/04Database Systems: Salman Azhar23 Oracle Problem With Field Access uYou can access a field F of an object that is the value of an attribute A by A.F. uHowever, you must use an alias, say tt, for the table T with attribute A, as tt.A.F.

2/1/04Database Systems: Salman Azhar24 Example: Field Access in Oracle uWrong (can’t have nothing): SELECT favCar.name FROM Buyers; uWrong (can’t have the table name): SELECT Buyers.favCar.name FROM Buyers; uRight (must have alias name): SELECT b.favCar.name FROM Buyers b;

2/1/04Database Systems: Salman Azhar25 Following References (REFs) uA  B denotes the value of the B component of the object pointed to by A uA  B makes sense if: 1.A is of type REF T 2.B is an attribute (component) of objects of type T

2/1/04Database Systems: Salman Azhar26 Following REF’s: Oracle Style uREF-following is implicit in the dot uJust follow a REF by a dot and a field of the object referred to uExample: SELECT ss.car.name FROM Sells ss WHERE ss.dealer.name = ‘AutoNation’; Field name in object car in table aliases as ss

2/1/04Database Systems: Salman Azhar27 Oracle’s DEREF Operator -- Motivation uIf we want the set of car objects for the cars sold by AutoNAtion, we might try: SELECT ss.car FROM Sells ss WHERE ss.dealer.name = ‘AutoNation’; uLegal, but ss.car is a REF, hence gibberish! wNeed to add DEREF object car (ref) in table aliases as ss

2/1/04Database Systems: Salman Azhar28 Using DEREF uTo see the CarType objects, use: SELECT DEREF(ss.car) FROM Sells ss WHERE ss.dealer.name = ‘AutoNation’; uProduces values like: CarType(‘MiniCooper’, ‘BMW’)

2/1/04Database Systems: Salman Azhar29 Methods uClasses are more than structures; they may have methods. wDeclare in CREATE TYPE wDefine methods in a CREATE TYPE BODY statement wUse T-SQL syntax for methods. (T-SQL: MS SQL Server = PL/SQL: Oracle) wVariable SELF refers to the object to which the method is applied (this)

2/1/04Database Systems: Salman Azhar30 Method Definition uForm of create-body statement: CREATE TYPE BODY AS PROCEDURE methodName(arg ) RETURN BEGIN … END;

2/1/04Database Systems: Salman Azhar31 Method Definition – Oracle Style Method definitions are called PL/SQL procedure definitions in Oracle Oracle uses “MEMBER FUNCTION” in place of “PROCEDURE”

2/1/04Database Systems: Salman Azhar32 Example: Method Definition CREATE TYPE BODY SellsType AS MEMBER FUNCTION priceConvert(rate FLOAT) RETURN FLOAT IS BEGIN RETURN rate * SELF.price; END; Argument & argument type Sorta like “this” keyword in C++/Java (parenthesis only if an argument is passed)

2/1/04Database Systems: Salman Azhar33 Method Use uobjectName.methodName(arguments if any) uExample: SELECT ss.car.name, ss.priceConvert(1.33) FROM Sells ss WHERE ss.dealer.name = ‘AutoNation’;

2/1/04Database Systems: Salman Azhar34 Example: Nested Table Type CREATE TYPE CarType AS OBJECT ( nameCHAR(20), editionCHAR(20) ); GO CREATE TYPE CarTableType AS TABLE OF CarType; GO

2/1/04Database Systems: Salman Azhar35 Example --- Continued uUse CarTableType in a Manfs relation that stores the set of cars by each manufacturer in one tuple for that manufacturer. CREATE TABLE Manfs ( nameCHAR(30), addrCHAR(50), carcarTableType );

2/1/04Database Systems: Salman Azhar36 Nested Tables uAllows values of row components to be whole relations uIf T is a UDT, wwe can create a type S whose values are relations with rowtype T, by: CREATE TYPE S AS TABLE OF T ;

2/1/04Database Systems: Salman Azhar37 Querying a Nested Table uWe can print the value of a nested table like any other value uBut these values have two type constructors: 1.For the table 2.For the type of tuples in the table

2/1/04Database Systems: Salman Azhar38 Example: Query a Nested Table uFind the cars by Toyota: SELECT car FROM Manfs WHERE name = ‘Toyota’; uProduces one value: CarTableType( CarType(‘Camry’, ‘LE’) CarType(‘Corolla’, ‘L’) …. )

2/1/04Database Systems: Salman Azhar39 Querying Within a Nested Table uA nested table can be converted to an ordinary relation by applying THE(…) uThis relation can be used in FROM clauses like any other relation

2/1/04Database Systems: Salman Azhar40 Example: Use of THE uFind the cars made by Toyota: SELECT dd.edition FROM THE( SELECT car FROM Manfs WHERE name = ‘Toyota’; ) dd WHERE dd.name = ‘Camry’;