9-Object Relational Model
9-Object Relational Model
Databases
Dr. M. Brindha
Assistant Professor
Department of CSE
NIT, Trichy-15
Object-Relational Data Models
• Extend the relational data model by including object
orientation and constructs to deal with added data
types.
• Allow attributes of tuples to have complex types,
including non-atomic values such as nested relations.
• Preserve relational foundations, in particular the
declarative access to data, while extending modeling
power.
• Upward compatibility with existing relational
languages.
Nested Relations
• Motivation:
• Permit non-atomic domains (atomic indivisible)
• Example of non-atomic domain: set of integers,or set of
tuples
• Allows more intuitive modeling for applications with
complex data
• Intuitive definition:
• allow relations whenever we allow atomic (scalar) values
— relations within relations
• Retains mathematical foundation of relational model
• Violates first normal form.
Example of a Nested Relation
• Example: library information system
• Each book has
• title,
• a set of authors,
• Publisher, and
• a set of keywords
flat-books
4NF Decomposition of Nested Relation
• Remove awkwardness of flat-books by assuming that the
following multivalued dependencies hold:
• title author
• title keyword
• title pub-name, pub-branch
• Decompose flat-doc into 4NF using the schemas:
• (title, author)
• (title, keyword)
• (title, pub-name, pub-branch)
4NF Decomposition of flat–books
Problems with 4NF Schema
• 4NF design requires users to include joins in their
queries.
• 1NF relational view flat-books defined by join of 4NF
relations:
• eliminates the need for users to perform joins,
• but loses the one-to-one correspondence between tuples and
documents.
• And has a large amount of redundancy
image blob(10MB)
movie blob (2GB)
• JDBC/ODBC provide special methods to access large
objects in small pieces
• Similar to accessing operating system files
• Application
retrieves a locator for the large object and then
manipulates the large object from the host language
Structured and Collection Types
• Structured types can be declared and used in SQL
• Storage alternatives
1. Store only local attributes and the primary key of the
supertable in subtable
• Inherited attributes derived by means of a join with the supertable
2. Each table stores all inherited and locally defined attributes
• Supertables implicitly contain (inherited attributes of) all tuples in
their subtables
• Access to all attributes of a tuple is faster: no join required
• If entities must have most specific type, tuple is stored only in one
table, where it was created
Otherwise, there could be redundancy
Reference Types
• Object-oriented languages provide the ability to create and
refer to objects.
• In SQL:1999
• References are to tuples, and
• References must be scoped,
• I.e., can only point to tuples in one specified table
• We will study how to define references first, and later see how
to use references
Reference Declaration in SQL:1999
• E.g. define a type Department with a field name and a
field head which is a reference to the type Person, with
table people as scope
create type Department(
name varchar(20),
head ref(Person) scope people)
• We can then create a table departments as follows
create table departments of Department
• We can omit the declaration scope people from the type
declaration and instead make an addition to the create
table statement:
create table departments of Department
(head with options scope people)
Initializing Reference Typed Values
• In Oracle,to create a tuple with a reference value, we can
first create the tuple with a null reference and then set
the reference separately by using the function ref(p)
applied to a tuple variable
• E.g. to create a department with name CS and head
being the person named John, we use
insert into departments
values (`CS’, null)
update departments
set head = (select ref(p)
from people as p
where name=`John’)
where name = `CS’
Initializing Reference Typed Values (Cont.)
• SQL:1999 does not support the ref() function, and instead requires a
special attribute to be declared to store the object identifier
• The self-referential attribute is declared by adding a ref is clause to
the create table statement:
create table people of Person
ref is oid system generated
•Here, oid is an attribute name, not a keyword.
• To get the reference to a tuple, the subquery shown earlier would
use
select p.oid
instead of select ref(p)
User Generated Identifiers
• SQL:1999 allows object identifiers to be user-generated
• The type of the object-identifier must be specified as part of the type
definition of the referenced table, and
• The table definition must specify that the reference is user generated
• E.g.