What Is an ORDBMS
An object-relational DBMS extends a relational DBMS with object concepts. It keeps tables and SQL but allows user-defined types, collections, references, inheritance and methods. These features were added to SQL by the SQL:1999 and SQL:2003 standards. Oracle, PostgreSQL and IBM DB2 are object-relational systems.
Features of the Object-Relational Model
- Structured (row) types: CREATE TYPE Address AS (street VARCHAR(30), city VARCHAR(20)).
- Collection types: ARRAY and MULTISET, so that an attribute may hold many values.
- Reference types: REF(type) holds a pointer to a row of an object table.
- Type and table inheritance: CREATE TYPE Student UNDER Person.
- Methods and large objects (BLOB for binary data, CLOB for text).
Nested Relations
The relational model requires first normal form (1NF): every attribute value is atomic. A nested relation (non-first-normal-form, NF²) allows an attribute value itself to be a relation, so a book can carry its set of authors in one tuple. Two operations convert between the forms: unnest (flatten) turns a set-valued attribute into one tuple per element, and nest groups tuples back into a set.
Design with Collections
- A multivalued attribute becomes a collection instead of a separate table.
- A weak entity can be nested inside its owner (the dependents of an employee).
- Generalization maps to table inheritance (UNDER).
- A relationship may be stored with REF attributes.
Advantages: fewer joins and a natural fit to application objects. Disadvantages: more complex queries, harder updates of nested data and redundancy if the same nested data appears in several tuples.
Definition: Nested relation. A relation in which the value of an attribute can itself be a relation, so that a set of values is stored inside one tuple.
Table 2.1: Flat and nested designs
| Point | Flat (1NF) | Nested (NF2) |
|---|---|---|
| Multivalued data | Extra table and join | Collection in the tuple |
| Query | Joins needed | Direct access |
| Update | Simple | More complex |
| Redundancy | Low | Possible |
Example 2.1: Unnest and nest
Problem: The nested relation BOOK(title, authors) has the tuples (DB Systems, {Asha, Bimal, Chitra}), (Algorithms, {Dev}) and (Networks, {Esha, Farid}). How many tuples are there after unnesting authors, and what does nesting them again give?
Solution:
- Unnest creates one tuple per author: 3 + 1 + 2 = 6 tuples.
- The flat relation has the pairs (DB Systems, Asha), (DB Systems, Bimal), (DB Systems, Chitra), (Algorithms, Dev), (Networks, Esha), (Networks, Farid).
- Nesting groups the 6 tuples by title, which gives 3 tuples again.
Result: Unnesting gives 6 tuples and nesting gives back the original 3 tuples.
import sqlite3
book = {"DB Systems": ["Asha", "Bimal", "Chitra"],
"Algorithms": ["Dev"], "Networks": ["Esha", "Farid"]}
flat = [(t, a) for t, authors in book.items() for a in authors]
print("Nested tuples:", len(book))
print("Unnested tuples:", len(flat))
db = sqlite3.connect(":memory:")
db.execute("CREATE TABLE ba(title TEXT, author TEXT)")
db.executemany("INSERT INTO ba VALUES (?, ?)", flat)
q = "SELECT title, group_concat(author) FROM ba GROUP BY title"
for row in db.execute(q):
print(row)
Output
Nested tuples: 3
Unnested tuples: 6
('Algorithms', 'Dev')
('DB Systems', 'Asha,Bimal,Chitra')
('Networks', 'Esha,Farid')
Common mistakes
- Nesting data that is shared by many tuples, which duplicates it.
- Forgetting that a nested design makes updates of single elements harder.
- Using collections where a separate table with its own key is needed.
- Assuming that object-relational means a pure object database.
Key takeaways
- ORDBMS = relational model + user-defined types, collections, references and inheritance.
- Nested relations break 1NF by allowing relation-valued attributes.
- Unnest flattens a collection; nest groups it again.
- Table inheritance (UNDER) models generalization.
Practice questions
- What is a nested relation?
- Name two collection types in SQL:1999.
- What does unnest do?
Answers to the practice questions
- A relation whose attribute values can be relations.
- ARRAY and MULTISET.
- Turns a set-valued attribute into one tuple per element.
Sources
- Official BCA syllabus Advanced Database Systems, course code 25BCA406DS04, Unit II
