Fall 2001Arthur Keller – CS 18014–1 Schedule Nov. 13 (T) Object-Relational, O-R Queries. u Read Sections 4.5, 9.4-9.5. Assignment 6 due. (No office hours.)

Slides:



Advertisements
Similar presentations
Union, Intersection, Difference (subquery) UNION (subquery) produces the union of the two relations. Similarly for INTERSECT, EXCEPT = intersection and.
Advertisements

SQL Group Members: Shijun Shen Xia Tang Sixin Qiang.
Winter 2002Arthur Keller – CS 1806–1 Schedule Today: Jan. 22 (T) u SQL Queries. u Read Sections Assignment 2 due. Jan. 24 (TH) u Subqueries, Grouping.
Chapter 5 Types. 5-2 Topics in this Chapter Values vs. Variables Types vs. Representations Type Definition Operators Type Generators SQL Facilities.
1 Object-Relational Databases User-Defined Types Object ID’s Nested Tables.
Fall 2001Arthur Keller – CS 18016–1 Schedule Nov. 20 (T) More OQL. u Read Sections Assignment 7 due (late ones by ). Nov. 22 (TH) Thanksgiving.
Fall 2001Arthur Keller – CS 18011–1 Schedule Oct. 30 (T) Embedded SQL. u Read Section 8.1. u Assignment 5 due. Not accepted late. u Project Part 4 due.
Winter 2002Arthur Keller – CS 18015–1 Schedule Today: Feb. 28 (TH) u Datalog and SQL Recursion, ODL. u Read Sections , Project Part 6.
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.
Fall 2001Arthur Keller – CS 1808–1 Schedule Today Oct. 18 (TH) Schemas, Views. u Read Sections u Project Part 3 extended to Oct. 23 (T). Oct.
2/1/04Database Systems: Salman Azhar1 Object-Relational Databases Salman Azhar User-Defined Types Object IDs Nested Tables These slides use some figures,
Object-Orientation in Query Languages By: Toan Nguyen Class: CS 157A.
Fall 2001Arthur Keller – CS 18015–1 Schedule Nov. 15 (TH) Object Queries (OQL). u Read Sections 9.1. Project Part 6 due on Sunday night. Nov. 20 (T) More.
Fall 2001Arthur Keller – CS 18010–1 Schedule Oct. 25 (TH) More Constraints, Triggers. u Read Sections Oct. 30 (T) Embedded SQL. u Read Section.
Winter 2002Arthur Keller – CS 1808–1 Schedule Today: Jan. 29 (T) u Modifications, Schemas, Views. u Read Sections Assignment 3 due. Jan. 31 (TH)
Winter 2002Arthur Keller – CS 18010–1 Schedule Today: Feb. 5 (T) u Triggers, PL/SQL. u Read Sections 7.4, 8.2. Assignment 4 due. Feb. 7 (TH) u PL/SQL,
Winter 2002Arthur Keller – CS 1809–1 Schedule Today: Jan. 31 (TH) u Constraints. u Read Sections , Project Part 3 due. Feb. 5 (T) u Triggers,
Winter 2002Arthur Keller – CS 18016–1 Schedule Today: Mar. 5 (T) u More ODL, OQL. u Read Sections 9.1. Assignment 7 due. Mar. 7 (TH) u More OQL. u Read.
Winter 2002Judy Cushing8–1 Schedule Jan. 30 (Wed) u Modifications, Schemas, Views. Read Sections This Week (Feb 4ff) u Constraints Read Sections.
Winter 2002Arthur Keller – CS 18018–1 Schedule Today: Mar. 12 (T) u Semistructured Data, XML, XQuery. u Read Sections Assignment 8 due. Mar. 14.
Fall 2001Arthur Keller – CS 1801–1 Computer Science 180: Database Systems Arthur M. Keller (best way to reach me) Office: Baskin.
Fall 2001Arthur Keller – CS 18012–1 Schedule Nov. 6 (T) Transactions, Authorization. u Read Sections Nov. 8 (TH) Object-Oriented Database Design.
Winter 2002Judy Cushing12–1 Schedule Today (week 8): u Object-Relational Systems. Sections 4.5, u Assignment 5 debriefed. u Transactions, Authorization.
Fall 2001Arthur Keller – CS 18017–1 Schedule Nov. 27 (T) Semistructured Data, XML. u Read Sections Assignment 8 due. Nov. 29 (TH) The Real World,
Winter 2002Arthur Keller – CS 18011–1 Schedule Today: Feb. 7 (TH) u PL/SQL, Embedded SQL, CLI, JDBC. u Read Sections 8.1, Feb. 12 (T) Advising.
Fall 2001Arthur Keller – CS 1809–1 Schedule Today Oct. 23 (T) Constraints. u Read Sections Assignment 4 due. Project Part 3 due Oct. 24 (W). Oct.
Winter 2002Arthur Keller – CS 1807–1 Schedule Today: Jan. 24 (TH) u Subqueries, Grouping and Aggregation. u Read Sections Project Part 2 due.
CPSC-608 Database Systems Fall 2011 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes #2.
PL/SQL Introduction Database 1. Practice. Sample Database The schema of the sample database is the following: Drinkers (name, occupation, birthday, salary)
Cursors in Pl/SQL Database 1. Practice. Sample Database The schema of the sample database is the following: Drinkers (name, occupation, birthday, salary)
ORDBS1 Object Relational Database Systems: 1. Introduction 2. Objects in SQL3 3. Comparison of ODL/OQL and SQL3 Approaches CIS 671.
SCUHolliday - coen 1789–1 Schedule Today: u Constraints, assertions, triggers u Read Sections , 7.4. Next u Triggers, PL/SQL, embedded SQL, JDBC.
Company LOGO OODB and XML Database Management Systems – Fall 2012 Matthew Moccaro.
1 Advanced Databases (CM036): Lecture # 5 ( Object-Relational and Nested-Relational Databases) Introduction to Object-Relational features of Oracle 9i.
Winter 2006Keller Ullman Cushing8–1 Turning in Assignments Please turn in hard copy (use only in the direst of circumstances). I am not your secretary.
1 Object-Relational Databases User-Defined Types Nested Tables.
Winter 2006Keller, Ullman, Cushing18–1 Plan 1.Information integration: important new application that motivates what follows. 2.Semistructured data: a.
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.
Winter 2006Keller, Ullman, Cushing12–1 Object-Relational Systems Object-oriented ideas enter the relational world. u Keep relation as the fundamental abstraction.
SCUHolliday - coen 1788–1 Schedule Today u Modifications, Schemas, Views. u Read Sections (except and 6.6.6) Next u Constraints. u Read.
Object-Relational SQL CIS 4301 Lecture Notes 4/20/2006.
1 Object-Relational Databases User-Defined Types Object ID’s Nested Tables.
Winter 2006 Keller, Ullman, Cushing 11–1 Embedded SQL Add to a conventional programming language (C in our examples) certain statements that represent.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
Object Relational Features
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.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 8 Object-Relational Database.
SCUHolliday - coen 1789–1 Schedule Today: u Constraints, assertions, triggers u Read Sections , 7.4. Next u Embedded SQL, JDBC. u Read Sections.
1 Introduction to Database Systems, CS420 SQL Persistent Stored Modules (PSM) – Stored Procedure.
CS422 Principles of Database Systems Object-Oriented Features in DBMS Chengyu Sun California State University, Los Angeles.
CPSC-310 Database Systems
Slides are reused by the approval of Jeffrey Ullman’s
Object-Relational Databases
CMSC-461 Database Management Systems
Schedule Today: Next After that Subqueries, Grouping and Aggregation.
Object-Relational DBMSs
CPSC-608 Database Systems
CPSC-608 Database Systems
Object-Relational Systems
Object-Relational Databases
Defining a Database Schema
Persistent Stored Modules (PSM) PL/SQL Embedded SQL
CMSC-461 Database Management Systems
CPSC-608 Database Systems
CPSC-608 Database Systems
CSC Database Management Systems
CMSC-461 Database Management Systems
Instructor: Zhe He Department of Computer Science
Presentation transcript:

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.) Nov. 15 (TH) Object Queries (OQL). u Read Sections 9.1. Project Part 6 due on Sunday night. Nov. 20 (T) More OQL. u Read Sections Assignment 7 due (no late ones). Nov. 22 (TH) Thanksgiving - No class scheduled. Nov. 27 (T) Semistructured Data, XML. u Read Sections Assignment 8 due. Project Part 7 due. Nov. 29 (TH) The Real World, Review. Dec. 3 (M) Final, 8–11AM.

Fall 2001Arthur Keller – CS 18014–2 Object-Relational Systems Object-oriented ideas enter the relational world. u Keep relation as the fundamental abstraction. Compare with “object-oriented DBMS,” which uses the class as the fundamental abstraction and tacks on relations as one of many types. Motivations Allow DBMS’s to deal with specialized types – maps, signals, images, etc. – with their own specialized methods. Supports specialized methods even on conventional relational data. Supports structure more complex than “flat files.”

Fall 2001Arthur Keller – CS 18014–3 Plan 1. Basic ideas from SQL standards documents. 2. Use Oracle 8i/9i notation when similar. 3. Introduce some new concepts from Oracle.

Fall 2001Arthur Keller – CS 18014–4 User-Defined Types SQL allows UDT’s that play a dual role: 1.They can be the types of relations; i.e., the type of their tuple. u Sometimes called a row type. 2.They can be the type of an attribute in a relation.

Fall 2001Arthur Keller – CS 18014–5 Defining UDT’s – Example in Oracle Syntax CREATE TYPE BarType AS OBJECT ( name CHAR(20) UNIQUE, addr CHAR(20) ); / CREATE TYPE BeerType AS OBJECT ( name CHAR(20) UNIQUE, manf CHAR(20) ); / CREATE TYPE MenuType AS OBJECT ( bar REF BarType, beer REF BeerType, price FLOAT ); /

Fall 2001Arthur Keller – CS 18014–6 Notes In Oracle, type definitions must be followed by a slash ( / ) in order to get them to compile. The SQL standard is similar, but “ OBJECT ” is not used after “ AS.”

Fall 2001Arthur Keller – CS 18014–7 Creating Tables Type declarations do not create tables. They are used in place of element lists in CREATE TABLE statements. Example CREATE TABLE Bars OF BarType; CREATE TABLE Beers OF BeerType; CREATE TABLE Sells OF MenuType;

Fall 2001Arthur Keller – CS 18014–8 Values of User-Defined Types – Oracle Approach Each UDT has a type constructor of the same name. Values of that type are the values of its fields wrapped in the constructor. Example SELECT * FROM Bars; produces values such as BarType('Joe''s Bar', 'Maple St.')

Fall 2001Arthur Keller – CS 18014–9 Accessing Fields of an Object – Oracle Approach The dot operator works as expected. Thus, if we want the bar name and address without the constructor: SELECT bb.name, bb.addr FROM Bars bb; The alias bb is not technically necessary, but there are other places where we must use an alias in order to access objects, and it is a good habit to use an alias always. SQL standard: Same idea, but the attribute is treated as a generator method, with parentheses, e.g., bb.name().

Fall 2001Arthur Keller – CS 18014–10 Inserting Values – Oracle Approach We can use the standard INSERT in Oracle, but we must wrap the inserted object in its type-constructor. Example INSERT INTO Bars VALUES( BarType('Joe''s Bar', 'Maple St.') ); SQL standard involves generator and mutator methods; see text.

Fall 2001Arthur Keller – CS 18014–11 Types for Columns A UDT can also be the type of a column. Example – Oracle Syntax Let’s create an address type for use with bars and drinkers. CREATE TYPE AddrType AS OBJECT ( street CHAR(30), city CHAR(20), zip INT ); We can then create a table of drinkers that includes their name, address, and favorite beer. The beer is included as a beer object, which “unnormalizes” the relation but is legal. CREATE TABLE Drinker ( name CHAR(30), addr AddrType, favBeer BeerType );

Fall 2001Arthur Keller – CS 18014–12 Need to Use Aliases If you access an attribute whose type is an object type, you must use an alias for the relation. E.g., SELECT favBeer.name FROM Drinker; will not work in Oracle; neither will: SELECT Drinker.favBeer.name FROM Drinker; You have to say: SELECT dd.favBeer.name FROM Drinker dd;

Fall 2001Arthur Keller – CS 18014–13 References UDT’s can have references. If T is a UDT, then REF(T) is the type of a reference to a T object. Unlike OO systems, refs are values that can be seen by queries.

Fall 2001Arthur Keller – CS 18014–14 Dereferencing in SQL A  B = the B attribute of the object referred to by reference A. Example Find the beers served by Joe. SELECT beer -> name FROM Sells WHERE bar -> name = 'Joe''s Bar';

Fall 2001Arthur Keller – CS 18014–15 Dereferencing in Oracle Dereferencing automatic, using dot operator. Example Same query in Oracle syntax: SELECT ss.beer.name FROM Sells ss WHERE ss.bar.name = 'Joe''s Bar';

Fall 2001Arthur Keller – CS 18014–16 Oracle’s DEREF Operator If we wanted the entire BeerType object, we might try to write SELECT ss.beer FROM Sells ss WHERE ss.bar.name = 'Joe''s Bar'; That is legal, but ss.beer is a reference, and we’d get a gibberish value. To see the whole beer object, use SELECT DEREF(ss.beer) FROM Sells ss WHERE ss.bar.name = 'Joe''s Bar';

Fall 2001Arthur Keller – CS 18014–17 Methods Real reason object-relational isn’t just nested structures in relations. We’ll follow Oracle syntax. Declared in a CREATE TYPE statement, defined in a CREATE TYPE BODY statement. Methods are functions or procedures; in Oracle they are defined like any PL/SQL procedure or function.  But, there is a special tuple variable SELF that refers to that object to which the method is applied.

Fall 2001Arthur Keller – CS 18014–18 Example Let’s add a method priceInYen to the MenuType and thus to the Sells relation. CREATE TYPE MenuType AS OBJECT ( bar REF BarType, beer REF BeerType, price FLOAT, MEMBER FUNCTION priceInYen( rate IN FLOAT) RETURN FLOAT, PRAGMA RESTRICT_REFERENCES(priceInYen, WNDS) ); CREATE TYPE BODY MenuType AS MEMBER FUNCTION priceInYen(rate FLOAT) RETURN FLOAT IS BEGIN RETURN rate * SELF.price; END; CREATE TABLE Sells OF MenuType;

Fall 2001Arthur Keller – CS 18014–19 Some Points to Remember The pragma is needed to allow priceInYen to be used in queries.  WNDS = “write no database state.” In the declaration, function/procedure arguments need a mode, IN, OUT, or IN OUT, just like PL/SQL procedures. u But the mode does not appear in the definition. Many methods will take no arguments (relying on the built-in “self”). u In that case, do not use parentheses after the function name. The body can have any number of function declarations, separated by semicolons.

Fall 2001Arthur Keller – CS 18014–20 Example of Method Use Follow a designator for the object to which you want to apply the method by a dot, the name of the method, and argument(s). SELECT ss.beer.name, ss.priceInYen(106.0) FROM Sells ss WHERE ss.bar.name = 'Joe''s Bar';

Fall 2001Arthur Keller – CS 18014–21 Built-In Comparison Functions (SQL3) We can define for each ADT two functions EQUAL and LESSTHAN. Allow values of this ADT to participate in WHERE clauses involving =, <=, etc. and in ORDER-BY sorting. Order Methods in Oracle 8 We can declare one method for a type to be an ORDER method. Definition of this method must return 0, if “self” is less than, equal to, or greater than the argument object. Also used in comparisons for WHERE and ORDER BY.

Fall 2001Arthur Keller – CS 18014–22 Example Order BarType objects by name. CREATE TYPE BarType AS OBJECT ( name CHAR(20) UNIQUE, addr CHAR(20), ORDER MEMBER FUNCTION before( bar2 IN BarType) RETURN INT, PRAGMA RESTRICT_REFERENCES(before, WNDS,RNDS,WNPS,RNPS) ); /

Fall 2001Arthur Keller – CS 18014–23 CREATE TYPE BODY BarType AS ORDER MEMBER FUNCTION before(bar2 BarType) RETURN INT IS BEGIN IF SELF.name < bar2.name THEN RETURN -1; ELSIF SELF.name = bar2.name THEN RETURN 0; ELSE RETURN 1; END IF; END; The extra codes in the pragma guarantee no reading or writing of the database state or the “package state.”