0% found this document useful (0 votes)
34 views

Lect3 Object Based Dbs

This document discusses object-based databases and type inheritance in Oracle. It covers creating object types that inherit attributes and methods from parent types, as well as table inheritance where subtables inherit from parent tables. The document also discusses object identity using system-generated, user-generated, and primary key identifiers for objects and references (REFs) that act as pointers between related objects. It provides examples of dereferencing REFs to access related object attributes.

Uploaded by

desireharsha
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

Lect3 Object Based Dbs

This document discusses object-based databases and type inheritance in Oracle. It covers creating object types that inherit attributes and methods from parent types, as well as table inheritance where subtables inherit from parent tables. The document also discusses object identity using system-generated, user-generated, and primary key identifiers for objects and references (REFs) that act as pointers between related objects. It provides examples of dereferencing REFs to access related object attributes.

Uploaded by

desireharsha
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 17

Object Based Dbs - 3

Lecture 3
Subject: ADBMS
Prepared by: Nirali Nanavati
Type Inheritance
 Create type PERSON_TY as object
(name varchar(20),
address varchar(25)) NOT FINAL;
 Create type STUDENT_TY under PERSON_TY

(degree varchar(20),
dept varchar(20));
 Create type TEACHER_TY under PERSON_TY

(salary number,
dept varchar(20));
 Create table student (st student_ty);
Type Inheritance Contd…

 Methods are inherited by subtypes


just like attributes.
 Subtype can redefine a
method/override it in place of the
method declared.
 Final/ not final must be specified after
type declaration.
Multiple Inheritance of Type
 Create type TA_TYPE under Student,
Teacher; //will this work?)
 The attributes name and address are
inherited from person; hence no
conflict.
 Create type TA_TYPE under
STUDENT_TY, with(dept as
stu_dept),TEACHER_TYPE with(dept
as teach_dept);
Table Inheritance
 Create table people of PERSON_TY;
 Create table students of STUDENT_TY
under people;
 Similarly table teachers.
 Subtables must be subtypes of type of
parent table.
 Tuples in students or teacher becomes
implicitly present in people. Is that true for
Oracle?
 Delete from people;
Table Inheritance Contd…

 Conceptually multiple inheritance is


possible
 Create table TA of TA_TYPE under
students, teachers;
 Each tuple of super table corresponds
to at most 1 tuple in the immediate
sub tables.
 What is the difference between NOT
FINAL and NOT INSTANCIABLE?
 What is the difference between
column objects and object tables?
Object identity and
Reference types
 A REF is a logical "pointer" to a row
object. It is an Oracle built-in datatype.
(Objects that appear in object tables
are called row objects. )
 Every row object in an object table
has an associated logical object
identifier (OID).
 REFs provide an easy mechanism for
navigating between objects.
Scoped REFs
 Scoped REF:
 E.g.

>
Create type DEPT_TY as object
(name varchar(20),
Head ref Person scope is people);
>
Create table departments of DEPT_TY;
Types of Identifiers:
System Generated
 Identifiers: System generated
 Oracle assigns a unique system-generated
identifier of length 16 bytes as the OID. The OID
column of an object table is a hidden column.
 Create type Person(name varchar(20), address
varchar(25));
 Create table people of Person ref is person_id system
generated
 Insert into departments values(‘CS’,null);
 Update departments set head = (select p.person_id
from people as p where name = ‘john’) where name =
‘CS’;
User Generated Identifier
 Identifier: User generated
 Create type Person(name varchar(20),
address varchar(25),
ref using varchar(20));
 Create table people of Person ref is
person_id user generated
 Insert into people
values(‘0123432’,’John’,’xyzstreet’);
 Insert into departments values (‘CS’,’
0123432’,);
Primary Key Identifier

 Identifier: Primary key


 Create type person(name varchar(20)
primary key, address varchar(25))ref
from (name);
 Create table people of Person ref is
person_id derived
 Insert into department
values(‘CS’,’John’);
Dereferencing
 Dereferencing:
 head->name = path expression.
 Select head->name, head->address
from departments where…;
 Select deref(head).name from
departments;
 Head is used to hide the join
operation.
System Generated
identifiers
 To see an OID assigned to each row,
 Select ref(P) from people P where
name = ‘john’;
 O/p – 16 bytes
Oracle 9i REF syntax..

 E.g.
>
Create type DEPT_TY as object
(name varchar(20),
Head ref Person );
>
 Update departments set head = (select REF(P) from
people P where name = ‘john’) where name = ‘CS’;
 Select d1.Head.name from departments d1 where where
name = ‘CS’ ;
Invalid references

 Delete from people where name = ‘John’;


 The record in departments that refers to the record in
people with name ‘John’ will have a dangling ‘REF’
 When you deleted the row object, the OID got deleted
and inserting a new row object will have a new OID,
hence the departments record will not recognize it as it
points to the old value
 In relational systems join is dependent on current data
 In OO systems, the join is between objects – 2 objects
having the same data doesn’t mean they are the
same.
Thank You

You might also like