Skip to content

Object-oriented Database

Object-Oriented Databases

Object Orientation gives us an object-relational data model. This has complex data types, and many beneficial features of OOP. Using SQL data directly in OOP is problematic, because you have to switch between SQL and the base language. To solve this, we can build an object-relational database, which adds OOP features to a relational database.

Creating "Objects"

User-Defined Types

CREATE TYPE person
    (ID varchar(20) primary key,
    name varchar(20),
    address varchar(100)) ref from(ID);
CREATE TABLE people OF person

Table Types

CREATE TYPE interest as TABLE(
    topic varchar(20),
    amount int
);
CREATE TABLE users (
    ID varchar(20),
    name varchar(20),
    interests interest
);

Inheritance

In MySQL, we can use the UNDER keyword to inherit (<child type> UNDER <parent type>) is the used syntax here. PostgreS and OracleDB use the INHERITS keyword to implement inheritance between tables as well.

CREATE TYPE student UNDER person
(degree varchar(20));