Chapter 3
Chapter 3
Model
Advanced databases
A. Chikhaoui
Faculty of Computer Science
USTHB
Tabel of Contents
1 Intoduction Collections
2 Abstract Data Types (ADT) 3 Object Identification (OID)
Definition 4 User-Defined Functions (UDFs)
Object table 5 Inheritance
data dictionary views 6 Large Object-LOB
Data Definition Language 7 Views
Data Manipulation Language 8 TRIGGERS
Index 9 Association in SQL3
A. Chikhaoui 2 / 88
Intoduction
Why the Object-Relational Model?
A. Chikhaoui Intoduction 4 / 88
Conceptual view of object-relational model
A. Chikhaoui Intoduction 5 / 88
Support from vendors
A. Chikhaoui Intoduction 6 / 88
Abstract Data Types (ADT)
Data Types
PERSON
ID NAME SALARY ADDRESS
NUM STREET CITY ZIPCODE
We can create a type for address It is then possible to use this ADT:
CREATE TYPE TADDRESS AS OBJECT ( CREATE TABLE PERSON (
NUM NUMBER, ID NUMBER,
STREET VARCHAR2(50), NAME VARCHAR2(25),
CITY VARCHAR2(25), SALARY NUMBER,
ZIPCODE NUMBER ADDRESS TADRESS
);/ );
OR
INSERT INTO PEOPLE VALUES (
(10, ’Ahmed’, TADDRESS(10, ‘STREET AHMED KATIB’, ’ALGIERS’, 16140)
);
Note: If the ADT belongs to another user, you must prefix it with the
owner’s name when using the constructor.
Example:
INSERT INTO PEOPLE VALUES (
(10, ’Ahmed’, OTHER USER.TADDRESS(10, ‘STREET AHMED KATIB’, ’ALGIERS’, 16140)
);
Basic syntax:
SELECT column1, column2, ...
FROM table name
WHERE condition;
To access the value of the city, the attributes of the ADT must be
specified using their full path with dot notation.
We use a correlation variable to access the attributes of the ADTs.
Examples:
SELECT NAME, P.ADDRESS.CITY FROM PEOPLE P;
UPDATE PEOPLE P
SET P.ADDRESS.CITY = ’ALGIERS’
WHERE P.ADDRESS.ZIPCODE LIKE ’16%’;
Example
CREATE OR REPLACE TYPE TLIST FNAMES AS
VARRAY(4) OF VARCHAR2(15);
/
▶ Example:
SELECT NOM, Q.*
FROM PEOPLE P, TABLE (P.FNAMES) Q;
The system expands the VARRAY into multiple rows, displaying each
element of the VARRAY separately.
LNAME COLUMN VALUE
ADLI AHMED
ADLI AKRAM
ADLI FADI
2. Step 2:
CREATE TYPE NT PROJECTS AS TABLE OF TPROJECT; /
3. Step 3:
CREATE TABLE DEPARTEMENT (
NUMDP VARCHAR2(25) PRIMARY KEY,
BUDGET NUMBER,
PROJECTS NT PROJECTS
)
NESTED TABLE PROJECTS STORE AS TABLE PROJECTS ;
Note: the clause NESTED tells that the column PROJECTS (which is a NT PROJECTS
nested table) should store its data in a separate physical table called TABLE PROJETS.
The column PROJECTS in DEPARTEMENT is not stored as a single field. Instead, its data
is stores in a separate table (TABLE PROJECTS), which is linked to DEPARTEMENT using
pointers.
A. Chikhaoui Abstract Data Types (ADT) Collections 32 / 88
NESTED TABLE V
DEPARTMENT
Numdpt Budget PROJECTS
D1 40500 id1
D2 50600 id2
Note: A Nested Table is not an object table; it does not associate an OID reference with a
collection item.
To perform group inserts (e.g. two people with the same addresses), CAST
and MULTISET are used.
▶ MULTISET(...): Creates a set (collection) of rows from a SELECT query.
▶ CAST(... AS TYPE): Converts the result into the correct nested table type.
Example:
INSERT INTO PEOPLE VALUES (
’Anes’,
CAST( MULTISET(
SELECT *
FROM TABLE (
SELECT ADDRESSES FROM PEOPLE WHERE PNAME = ’Ahmed’
)
) AS NT ADDRESS
)
);
This query:
▶ inserts a new person (Anes).
▶ copies all addresses from Ahmed and assigns them to Anes.
UPDATE TABLE can also be used to modify and delete tuples in the
nested table.
Example:
UPDATE TABLE
(SELECT ADDRESSES FROM PEOPLE WHERE PNAME = ’Ahmed’) adr
SET adr.CITY = ’ORAN’
WHERE adr.CITY = ’ALGIERS’;
The REF function allows to access the OID of the objects concerned.
REF(object) → the OID of the object
Example:
SELECT REF(P)
FROM PEOPLE P
WHERE P.NAME=’Ahmed’;
Relational Model
PERSON
NUMP ADDRESS SALARY NUMCAR NUMPROJECT
CAR
NUMCAR MODEL BRAND
PROJECT
NUMPROJECT AMOUNT DURATION
CAR
NUMCAR MODEL BRAND
PROJECT
NUMPROJECT AMOUNT DURATION
The insertion is performed using the REF function, which returns the
OID of a specified tuple (object).
Example:
INSERT INTO PEOPLE VALUES
(’ARKAM’, TLIST FNAME(’AHMED’,’FADI’),
(SELECT REF(C) FROM CARS C WHERE C.NUMCAR = ’1234567890’ ));
The DEREF function is the inverse of REF and is used to access the
associated object from an OID.
Example:
SELECT P.FNAME, P.LNAME, P.BIRTH DATE, DEREF(P.CAR)
FROM PEOPLE P
WHERE P.LNAME = ’YACINE’;
Output
FNAME LNAME BIRTH DATE @ CAR
FNAME type
Ahmed
Akram Yacine 16-05-1963 TCAR(12584, FIAT, 2025)
Anes
Now that TCar exists, we can fully define TPerson, which contains a
REF to TCar (the car the person owns).
CREATE TYPE TPerson AS OBJECT (
name VARCHAR2(50),
age NUMBER,
car REF TCar -- Reference to TCar (Owned car)
);
/
A. Chikhaoui Inheritance 65 / 88
Inheritance II
A. Chikhaoui Inheritance 66 / 88
Not instantiable type
A. Chikhaoui Inheritance 67 / 88
Table Storage for Supertypes and Subtypes I I
A. Chikhaoui Inheritance 68 / 88
Table Storage for Supertypes and Subtypes I
II
A. Chikhaoui Inheritance 69 / 88
Large Object-LOB
Large Object-LOB
A Large Object (LOB) is a data type that can store large amounts of
data, such as:
▶ Text files (e.g., books, articles, documents)
▶ Images (e.g., PNG, JPEG)
▶ Videos
▶ Audio files
SQL3 defines three main types of LOBs:
LOBs are useful when dealing with multimedia data or large text storage
in databases.
A. Chikhaoui Views 74 / 88
Steps for creating object views I
A. Chikhaoui Views 75 / 88
Steps for creating object views II
2. Creating abstract data types:
CREATE TYPE TADDRESS AS OBJECT (
STREET VARCHAR2(50),
CITY VARCHAR(25),
ZIPCODE NUMBER );
/
A. Chikhaoui Views 76 / 88
Steps for creating object views III
A. Chikhaoui Views 77 / 88
TRIGGERS
TRIGGERS I
A trigger is an active database rule that follows the
event-condition-action (ECA) model. This means:
▶ Event → A specific change occurs in the database (e.g., INSERT,
UPDATE, DELETE).
▶ Condition (optional) → A condition must be met before executing the
trigger.
▶ Action → The trigger performs an automatic operation (e.g., logging
changes, enforcing constraints).
They are stored procedures that execute automatically based on events.
Triggers allows to:
▶ Prevent Data Inconsistency (e.g., an order cannot be processed if the
stock is insufficient).
▶ Automatically Record Certain Events (tracking changes in a table. E.g. if
a user’s role is changed from ”Employee” to ”Admin,” tracking can alert
security teams.).
▶ Specify constraints related to data evolution (e.g. a salary can only
increase).
A. Chikhaoui TRIGGERS 79 / 88
TRIGGERS II
A. Chikhaoui TRIGGERS 80 / 88
TRIGGERS III
A. Chikhaoui TRIGGERS 81 / 88
TRIGGERS IV
A. Chikhaoui TRIGGERS 82 / 88
Association in SQL3
Transformation of associations I
Course eval
Eval std
Eval course
For the parent class (course), we add an attribute that stores the
references of the children (teachers) who taught this course, where
course teacher represents a nested table of teacher references.
For the child(teacher) class, we add an attribute that stores the
reference of the parent (course) taught by this teacher, where
teacher course represents the reference to the course taught.
For the student class, we add an attribute that stores the references of
the courses in which the student is enrolled, where student cours
represents a nested table of course references.
For the course class, we add an attribute that stores the references of
students enrolled in this course, where course student represents a
nested table of student references.