1. Inheritance can be at the level of types or at the level of tables.
2. Inheritance of types.
create type Person
(name MyString,
social-security integer)
create type Student
(degree MyString,
department MyString)
under Person
create type Teacher
(salary integer,
department MyString)
under Person
3. Multiple inheritance: Since name and social-security are inherited from a common source Person, there is no conflict by inheriting them from Student as well as Teacher. However, department is de ned separately in Student and Teacher, and one can rename them to avoid a conflict.
create type TeachingAssistant
under Student with (department as student-dept),
under Teacher with (department as teacher-dept)
4. Inheritance of tables:
To avoid creation of too many subtypes, one approach in the context of database systems is to allow an object to have multiple types without having a most speci c type.
Object-relational systems can model such a feature by using inheritance at the level of tables, rather than types, and allowing an entity to exist in more than one table at once.
create table people
(name MyString,
social-security integer)
create table students
(degree MyString,
department MyString)
under people
create table teachers
(salary integer,
department MyString)
under people
5. There are consistency requirements on subtables and supertables.
- Each tuple of supertable people can correspond to (i.e., having the same values for all inherited attributes as) at most one tuple in each of the tables students and teachers. (Why?)
- Each tuple in students and teachers must have exactly one corresponding tuple in people. (Why?)
6. Subtables can be stored in an ecient manner without replication of all inherited elds. Inherited attributes other than the primary key of the supertables can be derived by means of a join with the supertable, based on the primary key.
7. Multiple inheritance is possible with tables. A teaching-assistant can simply belong to the table students as well as to the table teacher. However, if we want, we can create a table for teaching-assistant entities as follows:
create type TeachingAssistant
under Student with (department as student-dept),
under Teacher with (department as student-dept)
Based on the consistency requirements for subtables, if an entity is present in the teaching-assistant table, it is also present in the teachers and in the students table.
8. Inheritance makes schema de nition natural, ensures referential and cardinality constraints, enables the use of functions de ned for supertypes on object belonging to subtypes, and allows the orderly extension of a database system to incorporate new types.
