You are on page 1of 97

Chapter 2

Yonas Y.

Outline

The Relational Data


Model Concepts
Relational Model
Concepts
Relational Model
Constraints and
Relational Database
Schemas
Update Operations,
Transactions, and
Dealing with
Constraint Violations
Chapter 2 Object and
Object-Relational
Data Models in DBMSs Databases
Overview of Object
Database Concepts
Extensible Markup
Language
Yonas Y. Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 1


Chapter 2

Yonas Y.

The Relational Data Model Concepts Outline


Relational Model Concepts The Relational Data
Relational Model Constraints and Relational Database Schemas Model Concepts
Relational Model
Update Operations, Transactions, and Dealing with Constraint Concepts
Relational Model
Violations Constraints and
Relational Database
Schemas
Update Operations,
Transactions, and
Dealing with
Constraint Violations
Object and Object-Relational Databases
Object and
Overview of Object Database Concepts Object-Relational
Databases
Overview of Object
Database Concepts
Extensible Markup
Extensible Markup Language Language
Structured,
Structured, Semistructured, and Unstructured Data Semistructured, and
Unstructured Data
XML Hierarchical (Tree) Data Model XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 2


Relational Model Concepts
The relational model represents the database as a collection of relations. Chapter 2
Informally, each relation resembles a table of values or, to some extent, Yonas Y.
a flat file of records.
Outline

The Relational Data


Model Concepts
Relational Model
Concepts
Relational Model
Constraints and
Relational Database
Schemas
Update Operations,
Transactions, and
Dealing with
Constraint Violations
Object and
Object-Relational
Databases
Overview of Object
Database Concepts
Extensible Markup
Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 3


Relational Model Concepts
The relational model represents the database as a collection of relations. Chapter 2
Informally, each relation resembles a table of values or, to some extent, Yonas Y.
a flat file of records.
Outline

When a relation is thought of as a table of values, each row in the table The Relational Data
Model Concepts
represents a collection of related data values. A row represents a fact Relational Model
Concepts
that typically corresponds to a real-world entity or relationship. Relational Model
Constraints and
Relational Database
Schemas
Update Operations,
Transactions, and
Dealing with
Constraint Violations
Object and
Object-Relational
Databases
Overview of Object
Database Concepts
Extensible Markup
Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 4


Relational Model Concepts
The relational model represents the database as a collection of relations. Chapter 2
Informally, each relation resembles a table of values or, to some extent, Yonas Y.
a flat file of records.
Outline

When a relation is thought of as a table of values, each row in the table The Relational Data
Model Concepts
represents a collection of related data values. A row represents a fact Relational Model
Concepts
that typically corresponds to a real-world entity or relationship. Relational Model
Constraints and
Relational Database
In the formal relational model terminology, a row is called a tuple, a Schemas
Update Operations,
column header is called an attribute, and the table is called a relation. Transactions, and
Dealing with
The data type describing the types of values that can appear in each Constraint Violations
Object and
column is represented by a domain of possible values. Object-Relational
Databases
Overview of Object
Database Concepts
Extensible Markup
Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 5


Relational Model Concepts
The relational model represents the database as a collection of relations. Chapter 2
Informally, each relation resembles a table of values or, to some extent, Yonas Y.
a flat file of records.
Outline

When a relation is thought of as a table of values, each row in the table The Relational Data
Model Concepts
represents a collection of related data values. A row represents a fact Relational Model
Concepts
that typically corresponds to a real-world entity or relationship. Relational Model
Constraints and
Relational Database
In the formal relational model terminology, a row is called a tuple, a Schemas
Update Operations,
column header is called an attribute, and the table is called a relation. Transactions, and
Dealing with
The data type describing the types of values that can appear in each Constraint Violations
Object and
column is represented by a domain of possible values. Object-Relational
Databases
Overview of Object
Domains, Attributes, Tuples, and Relations Database Concepts
Extensible Markup
A domain D specify the name, data type and format of the data values. Language
Some examples of domains follow: Structured,
Semistructured, and
Unstructured Data
I Names: The set of character strings that represent names of XML Hierarchical
(Tree) Data Model
persons.
I Grade point averages. Possible values of computed grade point

averages; each must be a real (floating-point) number between 0


and 4.
I Phone numbers. The set of ten-digit valid phone numbers.
AAiT - School of Electrical and Computer Engineering 6
A relation schema R, denoted by R(A1 , A2 , ..., An ), is made up of a Chapter 2

relation name R and a list of attributes A1 , A2 , ..., An . Each attribute Yonas Y.

Ai is the name of a role played by some domain D in the relation


Outline
schema R. The Relational Data
Model Concepts
I The domain of Ai is denoted by dom(Ai ). Relational Model
Concepts
I The degree (or arity) of a relation is the number of attributes n of Relational Model
Constraints and
its relation schema. Relational Database
Schemas
Update Operations,
Transactions, and
Dealing with
Constraint Violations
Object and
Object-Relational
Databases
Overview of Object
Database Concepts
Extensible Markup
Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 7


A relation schema R, denoted by R(A1 , A2 , ..., An ), is made up of a Chapter 2

relation name R and a list of attributes A1 , A2 , ..., An . Each attribute Yonas Y.

Ai is the name of a role played by some domain D in the relation


Outline
schema R. The Relational Data
Model Concepts
I The domain of Ai is denoted by dom(Ai ). Relational Model
Concepts
I The degree (or arity) of a relation is the number of attributes n of Relational Model
Constraints and
its relation schema. Relational Database
Schemas
Update Operations,
Transactions, and
Dealing with
A relation of degree five, which stores information about university Constraint Violations

students, would contain five attributes describing each student as Object and
Object-Relational
follows: Databases
Overview of Object
Database Concepts
STUDENT(Name, IDNo, Address, Age, Gpa)
Extensible Markup
Language
Using the data type of each attribute, the definition is sometimes Structured,
Semistructured, and
written as: Unstructured Data
XML Hierarchical
(Tree) Data Model
STUDENT(Name: string, IDNo: string, Address: string, Age: integer,
Gpa: real)

AAiT - School of Electrical and Computer Engineering 8


Chapter 2
A relation (or relation state) r of the relation schema R(A1 , A2 , ..., An ),
Yonas Y.
also denoted by r (R), is a set of n-tuples r = {t1 , t2 , ..., tm }.
Outline
Table 2.1 shows an example of a STUDENT relation, which corresponds The Relational Data
to the STUDENT schema just specified. Model Concepts
Relational Model
Concepts
STUDENT Relational Model
Constraints and
Name IDNo Address Age Gpa Relational Database
Schemas
Abebe A25446 A.A 21 3.10 Update Operations,
Transactions, and
Kebede K32564 Adama 23 3.05 Dealing with
Constraint Violations
Mahlet M88712 A.A 22 3.30 Object and
Object-Relational
Kemal K19256 Mekele NULL 3.22 Databases
Table: 2.1 The attributes and tuples of a relation STUDENT. Overview of Object
Database Concepts
Extensible Markup
Language
I Relation name STUDENT Structured,
Semistructured, and
Unstructured Data
I Attributes First row XML Hierarchical
(Tree) Data Model
I Tuples Rows except the first one

AAiT - School of Electrical and Computer Engineering 9


Characteristics of Relations
Ordering of Tuples in a Relation. A relation is defined as a set of Chapter 2
tuples. Tuples in a relation do not have any particular order. Yonas Y.
The definition of a relation does not specify any order: There is no
Outline
preference for one ordering over another.
The Relational Data
Model Concepts
Relational Model
Concepts
Relational Model
Constraints and
Relational Database
Schemas
Update Operations,
Transactions, and
Dealing with
Constraint Violations
Object and
Object-Relational
Databases
Overview of Object
Database Concepts
Extensible Markup
Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 10


Characteristics of Relations
Ordering of Tuples in a Relation. A relation is defined as a set of Chapter 2
tuples. Tuples in a relation do not have any particular order. Yonas Y.
The definition of a relation does not specify any order: There is no
Outline
preference for one ordering over another.
The Relational Data
Model Concepts
Ordering of Values within a Tuple and an Alternative Definition of Relational Model
Concepts
a Relation. According to the definition of a relation, an n-tuple is an Relational Model
Constraints and
ordered list of n values, so the ordering of values in a tuple-and hence of Relational Database
Schemas
attributes in a relation schema-is important. Update Operations,
Transactions, and
Dealing with
Constraint Violations
An alternative definition of a relation can be given, making the
Object and
ordering of values in a tuple unnecessary. According to this definition of Object-Relational
Databases
tuple as a mapping, a tuple can be considered as a set of Overview of Object
(< attribute >, < value >) pairs, where each pair gives the value of the Database Concepts
Extensible Markup
mapping from an attribute Ai to a value vi from dom(Ai ). Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 11


Characteristics of Relations
Ordering of Tuples in a Relation. A relation is defined as a set of Chapter 2
tuples. Tuples in a relation do not have any particular order. Yonas Y.
The definition of a relation does not specify any order: There is no
Outline
preference for one ordering over another.
The Relational Data
Model Concepts
Ordering of Values within a Tuple and an Alternative Definition of Relational Model
Concepts
a Relation. According to the definition of a relation, an n-tuple is an Relational Model
Constraints and
ordered list of n values, so the ordering of values in a tuple-and hence of Relational Database
Schemas
attributes in a relation schema-is important. Update Operations,
Transactions, and
Dealing with
Constraint Violations
An alternative definition of a relation can be given, making the
Object and
ordering of values in a tuple unnecessary. According to this definition of Object-Relational
Databases
tuple as a mapping, a tuple can be considered as a set of Overview of Object
(< attribute >, < value >) pairs, where each pair gives the value of the Database Concepts
Extensible Markup
mapping from an attribute Ai to a value vi from dom(Ai ). Language
Structured,
Semistructured, and
By this definition, the two tuples shown below are identical. Unstructured Data
XML Hierarchical
(Tree) Data Model
t = <(Name, Abebe), (Mobile phone, 0911-172545), (Address, A.A),
(Age, 21), (Gpa, 3.10)>

t = <(Address, A.A), (Name, Abebe), (Gpa, 3.10), (Age, 21),


(Mobile phone, 0911-172545)>
AAiT - School of Electrical and Computer Engineering 12
Chapter 2

Values and NULLs in the Tuples. NULL values are used to represent Yonas Y.

the values of attributes that may be unknown or may not apply to a Outline
tuple. The Relational Data
In general, we can have several meanings for NULL values, such as Model Concepts
Relational Model
value unknown, value exists but is not available, or attribute does not Concepts
Relational Model
apply to this tuple (also known as value undefined). Constraints and
Relational Database
Schemas
Update Operations,
Transactions, and
Dealing with
Constraint Violations
Object and
Object-Relational
Databases
Overview of Object
Database Concepts
Extensible Markup
Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 13


Chapter 2

Values and NULLs in the Tuples. NULL values are used to represent Yonas Y.

the values of attributes that may be unknown or may not apply to a Outline
tuple. The Relational Data
In general, we can have several meanings for NULL values, such as Model Concepts
Relational Model
value unknown, value exists but is not available, or attribute does not Concepts
Relational Model
apply to this tuple (also known as value undefined). Constraints and
Relational Database
Schemas
Update Operations,
Transactions, and
Interpretation (Meaning) of a Relation. The relation schema can be Dealing with
Constraint Violations
interpreted as a declaration or a type of assertion. Object and
For example, the schema of the STUDENT relation in table 2.1 asserts Object-Relational
Databases
that, in general, a student entity has a Name, IDNo, Address, Age, and Overview of Object
Database Concepts
Gpa.
Extensible Markup
Each tuple in the relation can then be interpreted as a fact or a Language
particular instance of the assertion. Structured,
Semistructured, and
Unstructured Data
For example, the first tuple of STUDENT asserts the fact that there is XML Hierarchical
a student whose Name is Abebe, Age is 21, and so on. (Tree) Data Model

AAiT - School of Electrical and Computer Engineering 14


Relational Model Notation
Chapter 2

Yonas Y.
We will use the following notation in our presentation:
Outline
I A relation schema R of degree n is denoted by R(A1 , A2 , ..., An ). The Relational Data
Model Concepts
I The uppercase letters Q, R, S denote relation names. Relational Model
Concepts
I The lowercase letters q, r, s denote relation states. Relational Model
Constraints and
Relational Database
I The letters t, u, v denote tuples. Schemas
Update Operations,
I In general, the name of a relation schema such as STUDENT also Transactions, and
Dealing with
indicates the current set of tuples in that relation-the current Constraint Violations
Object and
relation state-whereas STUDENT(Name, IDNo, ...) refers only to Object-Relational
the relation schema. Databases
Overview of Object
Database Concepts
I An attribute A can be qualified with the relation name R to which
Extensible Markup
it belongs by using the dot notation R.A - for example, Language
STUDENT.Name or STUDENT.Age. Structured,
Semistructured, and
Unstructured Data
I An n-tuple t in a relation r (R) is denoted by t =< v1 , v2 , ..., vn >, XML Hierarchical
(Tree) Data Model
where vi is the value corresponding to attribute Ai . The following
notation refers to component values of tuples.

AAiT - School of Electrical and Computer Engineering 15


Chapter 2

Yonas Y.
I Both t[Ai ] and t.Ai (and sometimes t[i]) refer to the value vi in t
for attribute Ai . Outline

The Relational Data


I Both t[Au , Aw , ..., Az ] and t.(Au , Aw , ..., Az ), where Au , Aw , ..., Az is Model Concepts
a list of attributes from R, refer to the subtuple of values Relational Model
Concepts
< vu , vw , ..., vz > from t corresponding to the attributes specified Relational Model
Constraints and
in the list. Relational Database
Schemas
Update Operations,
Transactions, and
Dealing with
Constraint Violations
As an example, consider the tuple Object and
Object-Relational
t = < Abebe, A25446, A.A, 21, 3.10> Databases
Overview of Object
Database Concepts
from the STUDENT relation in table 2.1; we have
Extensible Markup
Language
t[Name] = <Abebe>, and Structured,
Semistructured, and
Unstructured Data
t[IDNo, Age, Gpa] = <A25446, 21, 3.10>. XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 16


Relational Model Constraints and Relational Database Schemas
Chapter 2
In a relational database, there will typically be many relations, and the
Yonas Y.
tuples in those relations are usually related in various ways.
Outline
There are generally many restrictions or constraints on the actual The Relational Data
Model Concepts
values in a database state. These constraints are derived from the rules
Relational Model
in the miniworld that the database represents. Concepts
Relational Model
Constraints and
Relational Database
Schemas
Update Operations,
Transactions, and
Dealing with
Constraint Violations
Object and
Object-Relational
Databases
Overview of Object
Database Concepts
Extensible Markup
Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 17


Relational Model Constraints and Relational Database Schemas
Chapter 2
In a relational database, there will typically be many relations, and the
Yonas Y.
tuples in those relations are usually related in various ways.
Outline
There are generally many restrictions or constraints on the actual The Relational Data
Model Concepts
values in a database state. These constraints are derived from the rules
Relational Model
in the miniworld that the database represents. Concepts
Relational Model
Constraints and
Relational Database
Constraints on databases can generally be divided into three main Schemas
Update Operations,
categories: Transactions, and
Dealing with
Constraint Violations
1. Constraints that are inherent in the data model. We call these
Object and
inherent model-based constraints or implicit constraints. For Object-Relational
Databases
example, the constraint that a relation cannot have duplicate
Overview of Object
tuples is an inherent constraint. Database Concepts
Extensible Markup
Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 18


Relational Model Constraints and Relational Database Schemas
Chapter 2
In a relational database, there will typically be many relations, and the
Yonas Y.
tuples in those relations are usually related in various ways.
Outline
There are generally many restrictions or constraints on the actual The Relational Data
Model Concepts
values in a database state. These constraints are derived from the rules
Relational Model
in the miniworld that the database represents. Concepts
Relational Model
Constraints and
Relational Database
Constraints on databases can generally be divided into three main Schemas
Update Operations,
categories: Transactions, and
Dealing with
Constraint Violations
1. Constraints that are inherent in the data model. We call these
Object and
inherent model-based constraints or implicit constraints. For Object-Relational
Databases
example, the constraint that a relation cannot have duplicate
Overview of Object
tuples is an inherent constraint. Database Concepts
Extensible Markup
2. Constraints that can be directly expressed in schemas of the data Language

model, typically by specifying them in the DDL. We call these Structured,


Semistructured, and
Unstructured Data
schema-based constraints or explicit constraints. XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 19


Relational Model Constraints and Relational Database Schemas
Chapter 2
In a relational database, there will typically be many relations, and the
Yonas Y.
tuples in those relations are usually related in various ways.
Outline
There are generally many restrictions or constraints on the actual The Relational Data
Model Concepts
values in a database state. These constraints are derived from the rules
Relational Model
in the miniworld that the database represents. Concepts
Relational Model
Constraints and
Relational Database
Constraints on databases can generally be divided into three main Schemas
Update Operations,
categories: Transactions, and
Dealing with
Constraint Violations
1. Constraints that are inherent in the data model. We call these
Object and
inherent model-based constraints or implicit constraints. For Object-Relational
Databases
example, the constraint that a relation cannot have duplicate
Overview of Object
tuples is an inherent constraint. Database Concepts
Extensible Markup
2. Constraints that can be directly expressed in schemas of the data Language

model, typically by specifying them in the DDL. We call these Structured,


Semistructured, and
Unstructured Data
schema-based constraints or explicit constraints. XML Hierarchical
(Tree) Data Model
3. Constraints that cannot be directly expressed in the schemas of the
data model, and hence must be expressed and enforced by the
application programs. We call these application-based or
semantic constraints or business rules.

AAiT - School of Electrical and Computer Engineering 20


The schema-based constraints include domain constraints, key
constraints, constraints on NULLs, entity integrity constraints, and
referential integrity constraints. Chapter 2

Yonas Y.
I Domain Constraints
Domain constraints specify that within each tuple, the value of Outline

each attribute A must be an atomic value from the domain The Relational Data
Model Concepts
dom(A). Relational Model
The data types associated with domains typically include standard Concepts
Relational Model
numeric data types for integers (such as short integer, integer, and Constraints and
Relational Database
Schemas
long integer) and real numbers (float and double-precision float). Update Operations,
Characters, Booleans, fixed-length strings, and variable-length Transactions, and
Dealing with
Constraint Violations
strings are also available, as are date, time, timestamp, and money,
Object and
or other special data types. Object-Relational
Databases
Overview of Object
Database Concepts
Extensible Markup
Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 21


The schema-based constraints include domain constraints, key
constraints, constraints on NULLs, entity integrity constraints, and
referential integrity constraints. Chapter 2

Yonas Y.
I Domain Constraints
Domain constraints specify that within each tuple, the value of Outline

each attribute A must be an atomic value from the domain The Relational Data
Model Concepts
dom(A). Relational Model
The data types associated with domains typically include standard Concepts
Relational Model
numeric data types for integers (such as short integer, integer, and Constraints and
Relational Database
Schemas
long integer) and real numbers (float and double-precision float). Update Operations,
Characters, Booleans, fixed-length strings, and variable-length Transactions, and
Dealing with
Constraint Violations
strings are also available, as are date, time, timestamp, and money,
Object and
or other special data types. Object-Relational
Databases
I Key Constraints and Constraints on NULL Values Overview of Object
Database Concepts
In the relational model, no two tuples can have the same
Extensible Markup
combination of values for all their attributes. Usually, there are Language
Structured,
subsets of attributes of a relation schema R with the property Semistructured, and
Unstructured Data
that no two tuples in any relation state r of R should have the XML Hierarchical
(Tree) Data Model
same combination of values for these attributes.
Suppose that we denote one such subset of attributes by SK; then
for any two distinct tuples t1 and t2 in a relation state r of R, we
have the constraint that:
t1 [SK ] 6= t2 [SK ]
AAiT - School of Electrical and Computer Engineering 22
Any such set of attributes SK is called a superkey of the relation
schema R. Every relation has at least one default superkey-the set of all Chapter 2
its attributes. Yonas Y.

Outline

The Relational Data


Model Concepts
Relational Model
Concepts
Relational Model
Constraints and
Relational Database
Schemas
Update Operations,
Transactions, and
Dealing with
Constraint Violations
Object and
Object-Relational
Databases
Overview of Object
Database Concepts
Extensible Markup
Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 23


Any such set of attributes SK is called a superkey of the relation
schema R. Every relation has at least one default superkey-the set of all Chapter 2
its attributes. Yonas Y.

A key K of a relation schema R is a superkey of R with the additional Outline

property that removing any attribute A from K leaves a set of attributes The Relational Data
Model Concepts
K that is not a superkey of R any more. Hence, a key satisfies two Relational Model
Concepts
properties: Relational Model
Constraints and
1. Two distinct tuples in any state of the relation cannot have Relational Database
Schemas
identical values for (all) the attributes in the key. This first Update Operations,
Transactions, and
property also applies to a superkey. Dealing with
Constraint Violations

2. It is a minimal superkey -that is, a superkey from which we cannot Object and
Object-Relational
remove any attributes and still have the uniqueness constraint in Databases
Overview of Object
condition 1 hold. Database Concepts
Extensible Markup
Hence, a key is also a superkey but not vice versa. Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 24


Any such set of attributes SK is called a superkey of the relation
schema R. Every relation has at least one default superkey-the set of all Chapter 2
its attributes. Yonas Y.

A key K of a relation schema R is a superkey of R with the additional Outline

property that removing any attribute A from K leaves a set of attributes The Relational Data
Model Concepts
K that is not a superkey of R any more. Hence, a key satisfies two Relational Model
Concepts
properties: Relational Model
Constraints and
1. Two distinct tuples in any state of the relation cannot have Relational Database
Schemas
identical values for (all) the attributes in the key. This first Update Operations,
Transactions, and
property also applies to a superkey. Dealing with
Constraint Violations

2. It is a minimal superkey -that is, a superkey from which we cannot Object and
Object-Relational
remove any attributes and still have the uniqueness constraint in Databases
Overview of Object
condition 1 hold. Database Concepts
Extensible Markup
Hence, a key is also a superkey but not vice versa. Language
Structured,
Semistructured, and
Considering the STUDENT relation in table 2.1, the attribute set Unstructured Data
{IDNo} is a key of STUDENT because no two student tuples can have XML Hierarchical
(Tree) Data Model
the same value for phone number. Any set of attributes that includes
{IDNo} - for example, {IDNo, Name, Age} - is a superkey.
A key with multiple attributes must require all its attributes together to
have the uniqueness property.
AAiT - School of Electrical and Computer Engineering 25
In general, a relation schema may have more than one key. In this case,
each of the keys is called a candidate key. Chapter 2

Yonas Y.
For example,
Outline
The CAR relation in table 2.2 has two candidate keys: License number
The Relational Data
and Engine serial no. Model Concepts

It is common to designate one of the candidate keys as the primary key Relational Model
Concepts
of the relation, which is underlined. This is the candidate key whose Relational Model
Constraints and
values are used to identify tuples in the relation. The other candidate Relational Database
Schemas
keys are designated as unique keys, and are not underlined. Update Operations,
Transactions, and
Dealing with
Constraint Violations
CAR Object and
License number Engine serial no Make Model Year Object-Relational
Databases
(AA)(2)(A10253) A69352 Mercedes 190-D 99 Overview of Object
Database Concepts
(AA)(3)(79532) B43696 Toyota Yaris 02
Extensible Markup
(AA)(4)(55431) X83554 Toyota Corolla 94 Language
(SP)(4)(15230) U028365 Ford Mustang 00 Structured,
Semistructured, and
Table: 2.2 The CAR relation, with two candidate keys: License number and Unstructured Data
XML Hierarchical
Engine serial no. (Tree) Data Model

Another constraint on attributes specifies whether NULL values are


permitted or not.

AAiT - School of Electrical and Computer Engineering 26


Relational Databases and Relational Database Schemas
A relational database schema S is a set of relation schemas Chapter 2
S = R1 , R2 , ..., Rm and a set of integrity constraints IC. Yonas Y.

A relational database state DB of S is a set of relation states Outline

DB = r1 , r2 , ..., rm such that each ri is a state of Ri and such that the ri The Relational Data
Model Concepts
relation states satisfy the integrity constraints specified in IC. Relational Model
Concepts
Relational Model
Constraints and
Relational Database
Schemas
Update Operations,
Transactions, and
Dealing with
Constraint Violations
Object and
Object-Relational
Databases
Overview of Object
Database Concepts
Extensible Markup
Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 27


Relational Databases and Relational Database Schemas
A relational database schema S is a set of relation schemas Chapter 2
S = R1 , R2 , ..., Rm and a set of integrity constraints IC. Yonas Y.

A relational database state DB of S is a set of relation states Outline

DB = r1 , r2 , ..., rm such that each ri is a state of Ri and such that the ri The Relational Data
Model Concepts
relation states satisfy the integrity constraints specified in IC. Relational Model
Concepts
Relational Model
Figure 2.1 shows a relational database schema that we call Constraints and
Relational Database
COMPANY = {EMPLOYEE, DEPARTMENT, DEPT LOCATIONS, Schemas
Update Operations,
PROJECT, WORKS ON, DEPENDENT}. Transactions, and
Dealing with
Constraint Violations
EMPLOYEE Object and
Object-Relational
Name FName TinNo Bdate Sex Salary S TinNo Dno Databases
Overview of Object
Database Concepts
DEPARTMENT Extensible Markup
Language
Dname Dnumber Mgr TinNo Mgr start date Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
DEPT LOCATIONS (Tree) Data Model

Dnumber Dlocation

PROJECT
Pname Pnumber Plocation Dnum
AAiT - School of Electrical and Computer Engineering 28
WORKS ON
ETinNO Pno Hours
Chapter 2

DEPENDENT Yonas Y.

ETinNO Dependent name Sex Bdate Relationship Outline

The Relational Data


Figure 2.1 Schema diagram for the COMPANY relational database Model Concepts
Relational Model
schema. Concepts
Relational Model
Each relational DBMS must have a data definition language (DDL) for Constraints and
Relational Database
defining a relational database schema. Current relational DBMSs are Schemas
Update Operations,
mostly using SQL for this purpose. Transactions, and
Dealing with
Constraint Violations
Object and
Object-Relational
Databases
Overview of Object
Database Concepts
Extensible Markup
Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 29


WORKS ON
ETinNO Pno Hours
Chapter 2

DEPENDENT Yonas Y.

ETinNO Dependent name Sex Bdate Relationship Outline

The Relational Data


Figure 2.1 Schema diagram for the COMPANY relational database Model Concepts
Relational Model
schema. Concepts
Relational Model
Each relational DBMS must have a data definition language (DDL) for Constraints and
Relational Database
defining a relational database schema. Current relational DBMSs are Schemas
Update Operations,
mostly using SQL for this purpose. Transactions, and
Dealing with
Figure 2.2 shows a relational database state corresponding to the Constraint Violations
Object and
COMPANY schema. Object-Relational
Databases
EMPLOYEE Overview of Object
Database Concepts
Name FName TinNo Bdate Sex Salary S TinNo Dno
Extensible Markup
Marta Alemu 123456789 1965-01-09 F 3000 333445555
Language 5
Kebede Chala 333445555 1955-12-08 M 4000 888665555
Semistructured, 5
Structured,
and
Unstructured Data
Ahmed Nuredin 999887777 1968-01-19 M 2500 987654321
XML Hierarchical
4
(Tree) Data Model
Betelhem Atnaw 987654321 1941-06-20 F 4300 888665555 4
Tewodros Getachew 666884444 1962-09-15 M 3800 333445555 5
Meaza Dagnew 453453453 1972-07-31 F 2500 333445555 5
Gemechu Dabba 888665555 1969-03-29 M 2500 987654321 4
Abdurazak Mohammed 987987987 1937-11-10 M 5500 NULL 1
AAiT - School of Electrical and Computer Engineering 30
DEPARTMENT
Dname Dnumber Mgr TinNo Mgr start date
Chapter 2
Research 5 333445555 1988-05-22
Yonas Y.
Administration 4 987654321 1995-01-01
Headquarters 1 888665555 1981-06-19 Outline

The Relational Data


Model Concepts
Relational Model
Concepts
Relational Model
Constraints and
Relational Database
Schemas
Update Operations,
Transactions, and
Dealing with
Constraint Violations
Object and
Object-Relational
Databases
Overview of Object
Database Concepts
Extensible Markup
Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 31


DEPARTMENT
Dname Dnumber Mgr TinNo Mgr start date
Chapter 2
Research 5 333445555 1988-05-22
Yonas Y.
Administration 4 987654321 1995-01-01
Headquarters 1 888665555 1981-06-19 Outline

The Relational Data


Model Concepts
Relational Model
DEPT LOCATIONS Concepts
Dnumber Dlocation Relational Model
Constraints and
Relational Database
1 A.A Schemas
4 DireDawa Update Operations,
Transactions, and
Dealing with
5 Jimma Constraint Violations

5 Bahirdar Object and


Object-Relational
5 A.A Databases
Overview of Object
Database Concepts
Extensible Markup
Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 32


DEPARTMENT
Dname Dnumber Mgr TinNo Mgr start date
Chapter 2
Research 5 333445555 1988-05-22
Yonas Y.
Administration 4 987654321 1995-01-01
Headquarters 1 888665555 1981-06-19 Outline

The Relational Data


Model Concepts
Relational Model
DEPT LOCATIONS Concepts
Dnumber Dlocation Relational Model
Constraints and
Relational Database
1 A.A Schemas
4 DireDawa Update Operations,
Transactions, and
Dealing with
5 Jimma Constraint Violations

5 Bahirdar Object and


Object-Relational
5 A.A Databases
Overview of Object
Database Concepts
Extensible Markup
PROJECT Language
Pname Pnumber Plocation Dnum Structured,
Semistructured, and
ProductX 1 Jimma 5 Unstructured Data
XML Hierarchical
ProductY 2 Bahirdar 5 (Tree) Data Model

ProductZ 3 A.A 5
Computerization 10 DireDawa 4
Reorganization 20 A.A 1
Newbenefits 30 DireDawa 4
AAiT - School of Electrical and Computer Engineering 33
WORKS ON
ETinNO Pno Hours
123456789 1 32.5 Chapter 2

123456789 2 7.5 Yonas Y.

666884444 3 40.0 Outline

453453453 2 20.0 The Relational Data


Model Concepts
333445555 10 20.0 Relational Model
Concepts
333445555 20 20.0 Relational Model
Constraints and
999887777 30 30.0 Relational Database
Schemas
987987987 10 35.0 Update Operations,
Transactions, and
987654321 30 20.0 Dealing with
Constraint Violations
987654321 20 15.0
Object and
888665555 20 NULL Object-Relational
Databases
Overview of Object
Database Concepts
Extensible Markup
Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 34


WORKS ON
ETinNO Pno Hours
123456789 1 32.5 Chapter 2

123456789 2 7.5 Yonas Y.

666884444 3 40.0 Outline

453453453 2 20.0 The Relational Data


Model Concepts
333445555 10 20.0 Relational Model
Concepts
333445555 20 20.0 Relational Model
Constraints and
999887777 30 30.0 Relational Database
Schemas
987987987 10 35.0 Update Operations,
Transactions, and
987654321 30 20.0 Dealing with
Constraint Violations
987654321 20 15.0
Object and
888665555 20 NULL Object-Relational
Databases
Overview of Object
DEPENDENT Database Concepts

ETinNO Dependent name Sex Bdate Relationship Extensible Markup


Language
333445555 Selamawit F 1986-04-05 Daughter Structured,
Semistructured, and
333445555 Tigist F 1958-05-03 Spouse Unstructured Data
XML Hierarchical
987654321 Solomon M 1942-02-28 Spouse (Tree) Data Model

123456789 Yosef M 1988-01-04 Son


123456789 Kiros M 1967-05-05 Spouse

Figure 2.2 Schema diagram for the COMPANY relational database


AAiT - School of Electrical and Computer Engineering
schema. 35
Integrity, Referential Integrity, and Foreign Keys
The entity integrity constraint states that no primary key value can be Chapter 2

NULL. This is because the primary key value is used to identify Yonas Y.

individual tuples in a relation. Key constraints and entity integrity Outline


constraints are specified on individual relations. The Relational Data
Model Concepts
Relational Model
Concepts
Relational Model
Constraints and
Relational Database
Schemas
Update Operations,
Transactions, and
Dealing with
Constraint Violations
Object and
Object-Relational
Databases
Overview of Object
Database Concepts
Extensible Markup
Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 36


Integrity, Referential Integrity, and Foreign Keys
The entity integrity constraint states that no primary key value can be Chapter 2

NULL. This is because the primary key value is used to identify Yonas Y.

individual tuples in a relation. Key constraints and entity integrity Outline


constraints are specified on individual relations. The Relational Data
Model Concepts
Relational Model
The referential integrity constraint is specified between two relations Concepts
Relational Model
and is used to maintain the consistency among tuples in the two Constraints and
Relational Database
relations. Schemas
Update Operations,
Informally, the referential integrity constraint states that a tuple in one Transactions, and
Dealing with
relation that refers to another relation must refer to an existing tuple in Constraint Violations

that relation. Object and


Object-Relational
Databases
Overview of Object
Database Concepts
Extensible Markup
Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 37


Integrity, Referential Integrity, and Foreign Keys
The entity integrity constraint states that no primary key value can be Chapter 2

NULL. This is because the primary key value is used to identify Yonas Y.

individual tuples in a relation. Key constraints and entity integrity Outline


constraints are specified on individual relations. The Relational Data
Model Concepts
Relational Model
The referential integrity constraint is specified between two relations Concepts
Relational Model
and is used to maintain the consistency among tuples in the two Constraints and
Relational Database
relations. Schemas
Update Operations,
Informally, the referential integrity constraint states that a tuple in one Transactions, and
Dealing with
relation that refers to another relation must refer to an existing tuple in Constraint Violations

that relation. Object and


Object-Relational
Databases
A set of attributes FK in relation schema R1 is a foreign key of R1 that Overview of Object
Database Concepts
references relation R2 if it satisfies the following rules: Extensible Markup
Language
1. The attributes in FK have the same domain(s) as the primary key Structured,
attributes PK of R2 ; the attributes FK are said to reference or Semistructured, and
Unstructured Data
refer to the relation R2 . XML Hierarchical
(Tree) Data Model

2. A value of FK in a tuple t1 of the current state r1 (R1 ) either occurs


as a value of PK for some tuple t2 in the current state r2 (R2 ) or is
NULL. In the former case, we have t1 [FK ] = t2 [PK ], and we say
that the tuple t1 references or refers to the tuple t2 .
AAiT - School of Electrical and Computer Engineering 38
Chapter 2
In the above definition, R1 is called the referencing relation and R2 is
Yonas Y.
the referenced relation. Referential integrity constraints typically arise
from the relationships among the entities represented by the relation Outline
schemas. The Relational Data
Model Concepts
For example, Relational Model
Considering the database shown in figure 2.2; In the EMPLOYEE Concepts
Relational Model
relation, the attribute Dno refers to the department for which an Constraints and
Relational Database
employee works; hence, we designate Dno to be a foreign key of Schemas
Update Operations,
EMPLOYEE referencing the DEPARTMENT relation. Transactions, and
Dealing with
Constraint Violations
Object and
Object-Relational
Databases
Overview of Object
Database Concepts
Extensible Markup
Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 39


Chapter 2
In the above definition, R1 is called the referencing relation and R2 is
Yonas Y.
the referenced relation. Referential integrity constraints typically arise
from the relationships among the entities represented by the relation Outline
schemas. The Relational Data
Model Concepts
For example, Relational Model
Considering the database shown in figure 2.2; In the EMPLOYEE Concepts
Relational Model
relation, the attribute Dno refers to the department for which an Constraints and
Relational Database
employee works; hence, we designate Dno to be a foreign key of Schemas
Update Operations,
EMPLOYEE referencing the DEPARTMENT relation. Transactions, and
Dealing with
Constraint Violations

Notice that a foreign key can refer to its own relation. Object and
Object-Relational
For example, Databases
Overview of Object
The attribute S TinNo in EMPLOYEE refers to the supervisor of an Database Concepts
employee; this is another employee, represented by a tuple in the Extensible Markup
Language
EMPLOYEE relation. Hence, S TinNo is a foreign key that references Structured,
Semistructured, and
the EMPLOYEE relation itself. Unstructured Data
XML Hierarchical
(Tree) Data Model
The DDL includes provisions for specifying the various types of
constraints so that the DBMS can automatically enforce them.

AAiT - School of Electrical and Computer Engineering 40


Other Types of Constraints
The preceding integrity constraints are included in the DDL because Chapter 2
they occur in most database applications. However, they do not include Yonas Y.
a large class of general constraints, sometimes called semantic integrity
Outline
constraints, which may have to be specified and enforced on a relational
The Relational Data
database. Model Concepts
Relational Model
Examples of such constraints are Concepts
Relational Model
Constraints and
I the salary of an employee should not exceed the salary of the Relational Database
Schemas
employees supervisor and Update Operations,
Transactions, and
I the maximum number of hours an employee can work on all Dealing with
Constraint Violations
projects per week is 56. Object and
Object-Relational
Mechanisms called triggers and assertions can be used to achieve this Databases
Overview of Object
constraints. Database Concepts
Extensible Markup
Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 41


Other Types of Constraints
The preceding integrity constraints are included in the DDL because Chapter 2
they occur in most database applications. However, they do not include Yonas Y.
a large class of general constraints, sometimes called semantic integrity
Outline
constraints, which may have to be specified and enforced on a relational
The Relational Data
database. Model Concepts
Relational Model
Examples of such constraints are Concepts
Relational Model
Constraints and
I the salary of an employee should not exceed the salary of the Relational Database
Schemas
employees supervisor and Update Operations,
Transactions, and
I the maximum number of hours an employee can work on all Dealing with
Constraint Violations
projects per week is 56. Object and
Object-Relational
Mechanisms called triggers and assertions can be used to achieve this Databases
Overview of Object
constraints. Database Concepts
Extensible Markup
Another type of constraint is the functional dependency constraint, Language
Structured,
which establishes a functional relationship among two sets of attributes Semistructured, and
Unstructured Data
X and Y. This constraint specifies that the value of X determines a XML Hierarchical
(Tree) Data Model
unique value of Y in all states of a relation; it is denoted as a functional
dependency X Y .

AAiT - School of Electrical and Computer Engineering 42


Other Types of Constraints
The preceding integrity constraints are included in the DDL because Chapter 2
they occur in most database applications. However, they do not include Yonas Y.
a large class of general constraints, sometimes called semantic integrity
Outline
constraints, which may have to be specified and enforced on a relational
The Relational Data
database. Model Concepts
Relational Model
Examples of such constraints are Concepts
Relational Model
Constraints and
I the salary of an employee should not exceed the salary of the Relational Database
Schemas
employees supervisor and Update Operations,
Transactions, and
I the maximum number of hours an employee can work on all Dealing with
Constraint Violations
projects per week is 56. Object and
Object-Relational
Mechanisms called triggers and assertions can be used to achieve this Databases
Overview of Object
constraints. Database Concepts
Extensible Markup
Another type of constraint is the functional dependency constraint, Language
Structured,
which establishes a functional relationship among two sets of attributes Semistructured, and
Unstructured Data
X and Y. This constraint specifies that the value of X determines a XML Hierarchical
(Tree) Data Model
unique value of Y in all states of a relation; it is denoted as a functional
dependency X Y .
Another type of constraint, called transition constraints, can be defined
to deal with state changes in the database. An example of a transition
constraint is: the salary of an employee can only increase.
AAiT - School of Electrical and Computer Engineering 43
Update Operations, Transactions, and Dealing with Constraint
Violations Chapter 2

Yonas Y.
The operations of the relational model can be categorized into
retrievals and updates. Outline

There are three basic operations that can change the states of relations The Relational Data
Model Concepts
in the database: Insert, Delete, and Update (or Modify). Relational Model
Concepts
Relational Model
Constraints and
Relational Database
Schemas
Update Operations,
Transactions, and
Dealing with
Constraint Violations
Object and
Object-Relational
Databases
Overview of Object
Database Concepts
Extensible Markup
Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 44


Update Operations, Transactions, and Dealing with Constraint
Violations Chapter 2

Yonas Y.
The operations of the relational model can be categorized into
retrievals and updates. Outline

There are three basic operations that can change the states of relations The Relational Data
Model Concepts
in the database: Insert, Delete, and Update (or Modify). Relational Model
Concepts
Relational Model
The Insert Operation Constraints and
Relational Database
Schemas
The Insert operation provides a list of attribute values for a new tuple t Update Operations,
Transactions, and
Dealing with
that is to be inserted into a relation R. The main constraints that can Constraint Violations
be violated in this operation are : Object and
Object-Relational
I Domain constraints can be violated if an attribute value is given Databases
Overview of Object
that does not appear in the corresponding domain or is not of the Database Concepts

appropriate data type. Extensible Markup


Language
I Key constraints can be violated if a key value in the new tuple t Structured,
Semistructured, and
already exists in another tuple in the relation r (R). Unstructured Data
XML Hierarchical
(Tree) Data Model
I Entity integrity can be violated if any part of the primary key of
the new tuple t is NULL.
I Referential integrity can be violated if the value of any foreign key
in t refers to a tuple that does not exist in the referenced relation.
AAiT - School of Electrical and Computer Engineering 45
Here are some examples to illustrate this discussion.

Chapter 2

Yonas Y.

Outline

The Relational Data


Model Concepts
Relational Model
Concepts
Relational Model
Constraints and
Relational Database
Schemas
Update Operations,
Transactions, and
Dealing with
Constraint Violations
Object and
Object-Relational
Databases
Overview of Object
Database Concepts
Extensible Markup
Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 46


Here are some examples to illustrate this discussion.
I Operation: Chapter 2
Insert < Alemayehu, Melaku, NULL, 1960-04-05, M, 2800, Yonas Y.
333445555, 4> into EMPLOYEE.
Outline

The Relational Data


Model Concepts
Relational Model
Concepts
Relational Model
Constraints and
Relational Database
Schemas
Update Operations,
Transactions, and
Dealing with
Constraint Violations
Object and
Object-Relational
Databases
Overview of Object
Database Concepts
Extensible Markup
Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 47


Here are some examples to illustrate this discussion.
I Operation: Chapter 2
Insert < Alemayehu, Melaku, NULL, 1960-04-05, M, 2800, Yonas Y.
333445555, 4> into EMPLOYEE.
Outline
Result: This insertion violates the entity integrity constraint
The Relational Data
(NULL for the primary key TinNo), so it is rejected. Model Concepts
Relational Model
Concepts
Relational Model
Constraints and
Relational Database
Schemas
Update Operations,
Transactions, and
Dealing with
Constraint Violations
Object and
Object-Relational
Databases
Overview of Object
Database Concepts
Extensible Markup
Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 48


Here are some examples to illustrate this discussion.
I Operation: Chapter 2
Insert < Alemayehu, Melaku, NULL, 1960-04-05, M, 2800, Yonas Y.
333445555, 4> into EMPLOYEE.
Outline
Result: This insertion violates the entity integrity constraint
The Relational Data
(NULL for the primary key TinNo), so it is rejected. Model Concepts
Relational Model
I Operation: Concepts
Insert < Alemayehu, Melaku, 999887777, 1960-04-05, M, Relational Model
Constraints and
Relational Database
2800, 333445555, 5> into EMPLOYEE. Schemas
Update Operations,
Transactions, and
Dealing with
Constraint Violations
Object and
Object-Relational
Databases
Overview of Object
Database Concepts
Extensible Markup
Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 49


Here are some examples to illustrate this discussion.
I Operation: Chapter 2
Insert < Alemayehu, Melaku, NULL, 1960-04-05, M, 2800, Yonas Y.
333445555, 4> into EMPLOYEE.
Outline
Result: This insertion violates the entity integrity constraint
The Relational Data
(NULL for the primary key TinNo), so it is rejected. Model Concepts
Relational Model
I Operation: Concepts
Insert < Alemayehu, Melaku, 999887777, 1960-04-05, M, Relational Model
Constraints and
Relational Database
2800, 333445555, 5> into EMPLOYEE. Schemas
Result: This insertion violates the key constraint because another Update Operations,
Transactions, and
Dealing with
tuple with the same TinNo value already exists in the EMPLOYEE Constraint Violations
relation, and so it is rejected. Object and
Object-Relational
Databases
Overview of Object
Database Concepts
Extensible Markup
Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 50


Here are some examples to illustrate this discussion.
I Operation: Chapter 2
Insert < Alemayehu, Melaku, NULL, 1960-04-05, M, 2800, Yonas Y.
333445555, 4> into EMPLOYEE.
Outline
Result: This insertion violates the entity integrity constraint
The Relational Data
(NULL for the primary key TinNo), so it is rejected. Model Concepts
Relational Model
I Operation: Concepts
Insert < Alemayehu, Melaku, 999887777, 1960-04-05, M, Relational Model
Constraints and
Relational Database
2800, 333445555, 5> into EMPLOYEE. Schemas
Result: This insertion violates the key constraint because another Update Operations,
Transactions, and
Dealing with
tuple with the same TinNo value already exists in the EMPLOYEE Constraint Violations
relation, and so it is rejected. Object and
Object-Relational
I Operation: Databases
Overview of Object
Insert < Alemayehu, Melaku, 999445777, 1960-04-05, M, Database Concepts

2800, 333445555, 7> into EMPLOYEE. Extensible Markup


Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 51


Here are some examples to illustrate this discussion.
I Operation: Chapter 2
Insert < Alemayehu, Melaku, NULL, 1960-04-05, M, 2800, Yonas Y.
333445555, 4> into EMPLOYEE.
Outline
Result: This insertion violates the entity integrity constraint
The Relational Data
(NULL for the primary key TinNo), so it is rejected. Model Concepts
Relational Model
I Operation: Concepts
Insert < Alemayehu, Melaku, 999887777, 1960-04-05, M, Relational Model
Constraints and
Relational Database
2800, 333445555, 5> into EMPLOYEE. Schemas
Result: This insertion violates the key constraint because another Update Operations,
Transactions, and
Dealing with
tuple with the same TinNo value already exists in the EMPLOYEE Constraint Violations
relation, and so it is rejected. Object and
Object-Relational
I Operation: Databases
Overview of Object
Insert < Alemayehu, Melaku, 999445777, 1960-04-05, M, Database Concepts

2800, 333445555, 7> into EMPLOYEE. Extensible Markup


Language
Result: This insertion violates the referential integrity constraint Structured,
Semistructured, and
specified on Dno in EMPLOYEE because no corresponding Unstructured Data
XML Hierarchical
referenced tuple exists in DEPARTMENT with Dnumber = 7. (Tree) Data Model

AAiT - School of Electrical and Computer Engineering 52


Here are some examples to illustrate this discussion.
I Operation: Chapter 2
Insert < Alemayehu, Melaku, NULL, 1960-04-05, M, 2800, Yonas Y.
333445555, 4> into EMPLOYEE.
Outline
Result: This insertion violates the entity integrity constraint
The Relational Data
(NULL for the primary key TinNo), so it is rejected. Model Concepts
Relational Model
I Operation: Concepts
Insert < Alemayehu, Melaku, 999887777, 1960-04-05, M, Relational Model
Constraints and
Relational Database
2800, 333445555, 5> into EMPLOYEE. Schemas
Result: This insertion violates the key constraint because another Update Operations,
Transactions, and
Dealing with
tuple with the same TinNo value already exists in the EMPLOYEE Constraint Violations
relation, and so it is rejected. Object and
Object-Relational
I Operation: Databases
Overview of Object
Insert < Alemayehu, Melaku, 999445777, 1960-04-05, M, Database Concepts

2800, 333445555, 7> into EMPLOYEE. Extensible Markup


Language
Result: This insertion violates the referential integrity constraint Structured,
Semistructured, and
specified on Dno in EMPLOYEE because no corresponding Unstructured Data
XML Hierarchical
referenced tuple exists in DEPARTMENT with Dnumber = 7. (Tree) Data Model

I Operation:
Insert < Alemayehu, Melaku, 999445777, 1960-04-05, M,
2800, 333445555, 4> into EMPLOYEE.

AAiT - School of Electrical and Computer Engineering 53


Here are some examples to illustrate this discussion.
I Operation: Chapter 2
Insert < Alemayehu, Melaku, NULL, 1960-04-05, M, 2800, Yonas Y.
333445555, 4> into EMPLOYEE.
Outline
Result: This insertion violates the entity integrity constraint
The Relational Data
(NULL for the primary key TinNo), so it is rejected. Model Concepts
Relational Model
I Operation: Concepts
Insert < Alemayehu, Melaku, 999887777, 1960-04-05, M, Relational Model
Constraints and
Relational Database
2800, 333445555, 5> into EMPLOYEE. Schemas
Result: This insertion violates the key constraint because another Update Operations,
Transactions, and
Dealing with
tuple with the same TinNo value already exists in the EMPLOYEE Constraint Violations
relation, and so it is rejected. Object and
Object-Relational
I Operation: Databases
Overview of Object
Insert < Alemayehu, Melaku, 999445777, 1960-04-05, M, Database Concepts

2800, 333445555, 7> into EMPLOYEE. Extensible Markup


Language
Result: This insertion violates the referential integrity constraint Structured,
Semistructured, and
specified on Dno in EMPLOYEE because no corresponding Unstructured Data
XML Hierarchical
referenced tuple exists in DEPARTMENT with Dnumber = 7. (Tree) Data Model

I Operation:
Insert < Alemayehu, Melaku, 999445777, 1960-04-05, M,
2800, 333445555, 4> into EMPLOYEE.
Result:This insertion satisfies all constraints, so it is acceptable.
AAiT - School of Electrical and Computer Engineering 54
The Delete Operation
Chapter 2
The Delete operation can violate only referential integrity. This occurs Yonas Y.
if the tuple being deleted is referenced by foreign keys from other tuples
Outline
in the database.
The Relational Data
Here are some examples. Model Concepts
Relational Model
I Operation: Concepts
Relational Model
Delete the WORKS ON tuple with ETinNo = 999887777 and Constraints and
Relational Database
Pno = 30. Schemas
Update Operations,
Result:This deletion is acceptable and deletes exactly one tuple. Transactions, and
Dealing with
Constraint Violations
Object and
Object-Relational
Databases
Overview of Object
Database Concepts
Extensible Markup
Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 55


The Delete Operation
Chapter 2
The Delete operation can violate only referential integrity. This occurs Yonas Y.
if the tuple being deleted is referenced by foreign keys from other tuples
Outline
in the database.
The Relational Data
Here are some examples. Model Concepts
Relational Model
I Operation: Concepts
Relational Model
Delete the WORKS ON tuple with ETinNo = 999887777 and Constraints and
Relational Database
Pno = 30. Schemas
Update Operations,
Result:This deletion is acceptable and deletes exactly one tuple. Transactions, and
Dealing with
I Operation: Constraint Violations
Object and
Delete the EMPLOYEE tuple with TinNo = 999887777. Object-Relational
Result:This deletion is not acceptable, because there are tuples in Databases
Overview of Object
WORKS ON that refer to this tuple. Hence, if the tuple in Database Concepts

EMPLOYEE is deleted, referential integrity violations will result. Extensible Markup


Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 56


The Delete Operation
Chapter 2
The Delete operation can violate only referential integrity. This occurs Yonas Y.
if the tuple being deleted is referenced by foreign keys from other tuples
Outline
in the database.
The Relational Data
Here are some examples. Model Concepts
Relational Model
I Operation: Concepts
Relational Model
Delete the WORKS ON tuple with ETinNo = 999887777 and Constraints and
Relational Database
Pno = 30. Schemas
Update Operations,
Result:This deletion is acceptable and deletes exactly one tuple. Transactions, and
Dealing with
I Operation: Constraint Violations
Object and
Delete the EMPLOYEE tuple with TinNo = 999887777. Object-Relational
Result:This deletion is not acceptable, because there are tuples in Databases
Overview of Object
WORKS ON that refer to this tuple. Hence, if the tuple in Database Concepts

EMPLOYEE is deleted, referential integrity violations will result. Extensible Markup


Language
I Operation: Structured,
Semistructured, and
Delete the EMPLOYEE tuple with TinNo =333445555. Unstructured Data
XML Hierarchical
Result:This deletion will result in even worse referential integrity (Tree) Data Model

violations, because the tuple involved is referenced by tuples from


the EMPLOYEE, DEPARTMENT, WORKS ON, and
DEPENDENT relations.

AAiT - School of Electrical and Computer Engineering 57


Several options are available if a deletion operation causes a violation.
I The first option, called restrict, is to reject the deletion.
Chapter 2
I The second option, called cascade, is to attempt to cascade (or Yonas Y.
propagate) the deletion by deleting tuples that reference the tuple
Outline
that is being deleted.
The Relational Data
I A third option, called set null or set default, is to modify the Model Concepts
Relational Model
referencing attribute values that cause the violation; each such Concepts
Relational Model
value is either set to NULL or changed to reference another default Constraints and
Relational Database
valid tuple. Schemas
Update Operations,
Transactions, and
Dealing with
Constraint Violations
Object and
Object-Relational
Databases
Overview of Object
Database Concepts
Extensible Markup
Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 58


Several options are available if a deletion operation causes a violation.
I The first option, called restrict, is to reject the deletion.
Chapter 2
I The second option, called cascade, is to attempt to cascade (or Yonas Y.
propagate) the deletion by deleting tuples that reference the tuple
Outline
that is being deleted.
The Relational Data
I A third option, called set null or set default, is to modify the Model Concepts
Relational Model
referencing attribute values that cause the violation; each such Concepts
Relational Model
value is either set to NULL or changed to reference another default Constraints and
Relational Database
valid tuple. Schemas
Update Operations,
Transactions, and
The Update Operation Dealing with
Constraint Violations

The Update (or Modify) operation is used to change the values of one Object and
Object-Relational
or more attributes in a tuple (or tuples) of some relation R. Databases

Here are some examples. Overview of Object


Database Concepts
Extensible Markup
Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 59


Several options are available if a deletion operation causes a violation.
I The first option, called restrict, is to reject the deletion.
Chapter 2
I The second option, called cascade, is to attempt to cascade (or Yonas Y.
propagate) the deletion by deleting tuples that reference the tuple
Outline
that is being deleted.
The Relational Data
I A third option, called set null or set default, is to modify the Model Concepts
Relational Model
referencing attribute values that cause the violation; each such Concepts
Relational Model
value is either set to NULL or changed to reference another default Constraints and
Relational Database
valid tuple. Schemas
Update Operations,
Transactions, and
The Update Operation Dealing with
Constraint Violations

The Update (or Modify) operation is used to change the values of one Object and
Object-Relational
or more attributes in a tuple (or tuples) of some relation R. Databases

Here are some examples. Overview of Object


Database Concepts

I Operation: Extensible Markup


Language
Update the salary of the EMPLOYEE tuple with TinNo = Structured,
Semistructured, and
999887777 to 2800. Unstructured Data
XML Hierarchical
Result:Acceptable. (Tree) Data Model

AAiT - School of Electrical and Computer Engineering 60


Several options are available if a deletion operation causes a violation.
I The first option, called restrict, is to reject the deletion.
Chapter 2
I The second option, called cascade, is to attempt to cascade (or Yonas Y.
propagate) the deletion by deleting tuples that reference the tuple
Outline
that is being deleted.
The Relational Data
I A third option, called set null or set default, is to modify the Model Concepts
Relational Model
referencing attribute values that cause the violation; each such Concepts
Relational Model
value is either set to NULL or changed to reference another default Constraints and
Relational Database
valid tuple. Schemas
Update Operations,
Transactions, and
The Update Operation Dealing with
Constraint Violations

The Update (or Modify) operation is used to change the values of one Object and
Object-Relational
or more attributes in a tuple (or tuples) of some relation R. Databases

Here are some examples. Overview of Object


Database Concepts

I Operation: Extensible Markup


Language
Update the salary of the EMPLOYEE tuple with TinNo = Structured,
Semistructured, and
999887777 to 2800. Unstructured Data
XML Hierarchical
Result:Acceptable. (Tree) Data Model

I Operation:
Update the Dno of the EMPLOYEE tuple with TinNo =
999887777 to 1.
Result:Acceptable.
AAiT - School of Electrical and Computer Engineering 61
I Operation:
Update the Dno of the EMPLOYEE tuple with TinNo = Chapter 2
999887777 to 7. Yonas Y.
Result:Unacceptable, because it violates referential integrity.
Outline

The Relational Data


Model Concepts
Relational Model
Concepts
Relational Model
Constraints and
Relational Database
Schemas
Update Operations,
Transactions, and
Dealing with
Constraint Violations
Object and
Object-Relational
Databases
Overview of Object
Database Concepts
Extensible Markup
Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 62


I Operation:
Update the Dno of the EMPLOYEE tuple with TinNo = Chapter 2
999887777 to 7. Yonas Y.
Result:Unacceptable, because it violates referential integrity.
Outline
I Operation: The Relational Data
Update the Ssn of the EMPLOYEE tuple with TinNo = Model Concepts
Relational Model
999887777 to 987654321. Concepts
Relational Model
Result:Unacceptable, because it violates primary key constraint by Constraints and
Relational Database
repeating a value that already exists as a primary key in another Schemas
Update Operations,
tuple; it violates referential integrity constraints because there are Transactions, and
Dealing with
other relations that refer to the existing value of TinNo. Constraint Violations
Object and
Object-Relational
Databases
Overview of Object
Database Concepts
Extensible Markup
Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 63


I Operation:
Update the Dno of the EMPLOYEE tuple with TinNo = Chapter 2
999887777 to 7. Yonas Y.
Result:Unacceptable, because it violates referential integrity.
Outline
I Operation: The Relational Data
Update the Ssn of the EMPLOYEE tuple with TinNo = Model Concepts
Relational Model
999887777 to 987654321. Concepts
Relational Model
Result:Unacceptable, because it violates primary key constraint by Constraints and
Relational Database
repeating a value that already exists as a primary key in another Schemas
Update Operations,
tuple; it violates referential integrity constraints because there are Transactions, and
Dealing with
other relations that refer to the existing value of TinNo. Constraint Violations
Object and
Updating an attribute that is neither part of a primary key nor of a Object-Relational
Databases
foreign key usually causes no problems; the DBMS need only check to Overview of Object
Database Concepts
confirm that the new value is of the correct data type and domain.
Extensible Markup
Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 64


I Operation:
Update the Dno of the EMPLOYEE tuple with TinNo = Chapter 2
999887777 to 7. Yonas Y.
Result:Unacceptable, because it violates referential integrity.
Outline
I Operation: The Relational Data
Update the Ssn of the EMPLOYEE tuple with TinNo = Model Concepts
Relational Model
999887777 to 987654321. Concepts
Relational Model
Result:Unacceptable, because it violates primary key constraint by Constraints and
Relational Database
repeating a value that already exists as a primary key in another Schemas
Update Operations,
tuple; it violates referential integrity constraints because there are Transactions, and
Dealing with
other relations that refer to the existing value of TinNo. Constraint Violations
Object and
Updating an attribute that is neither part of a primary key nor of a Object-Relational
Databases
foreign key usually causes no problems; the DBMS need only check to Overview of Object
Database Concepts
confirm that the new value is of the correct data type and domain.
Extensible Markup
Language
The Transaction Concept Structured,
Semistructured, and
Unstructured Data
A transaction is an executing program that includes some database XML Hierarchical
(Tree) Data Model
operations, such as reading from the database, or applying insertions,
deletions, or updates to the database.
At the end of the transaction, it must leave the database in a valid or
consistent state that satisfies all the constraints specified on the
database schema.
AAiT - School of Electrical and Computer Engineering 65
Object and Object-Relational Databases
Chapter 2

Yonas Y.
Traditional data models and systems, such as relational, network, and
hierarchical, have been quite successful in developing the database Outline

technologies required for many traditional business database The Relational Data
Model Concepts
applications. Relational Model
Concepts
Relational Model
Constraints and
Relational Database
Schemas
Update Operations,
Transactions, and
Dealing with
Constraint Violations
Object and
Object-Relational
Databases
Overview of Object
Database Concepts
Extensible Markup
Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 66


Object and Object-Relational Databases
Chapter 2

Yonas Y.
Traditional data models and systems, such as relational, network, and
hierarchical, have been quite successful in developing the database Outline

technologies required for many traditional business database The Relational Data
Model Concepts
applications. Relational Model
Concepts
Relational Model
However, they have certain shortcomings when more complex database Constraints and
Relational Database
applications must be designed and implemented - for example, Schemas
Update Operations,
databases for engineering design and manufacturing (CAD/CAM and Transactions, and
Dealing with
CIM), scientific experiments, telecommunications, geographic Constraint Violations

information systems, and multimedia. Object databases were proposed Object and
Object-Relational
to meet some of the needs of these more complex applications. Databases
Overview of Object
Database Concepts
Extensible Markup
Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 67


Object and Object-Relational Databases
Chapter 2

Yonas Y.
Traditional data models and systems, such as relational, network, and
hierarchical, have been quite successful in developing the database Outline

technologies required for many traditional business database The Relational Data
Model Concepts
applications. Relational Model
Concepts
Relational Model
However, they have certain shortcomings when more complex database Constraints and
Relational Database
applications must be designed and implemented - for example, Schemas
Update Operations,
databases for engineering design and manufacturing (CAD/CAM and Transactions, and
Dealing with
CIM), scientific experiments, telecommunications, geographic Constraint Violations

information systems, and multimedia. Object databases were proposed Object and
Object-Relational
to meet some of the needs of these more complex applications. Databases
Overview of Object
Database Concepts
A key features of object databases are:
Extensible Markup
Language
I Give the designer power to specify both the structure of complex
Structured,
objects and the operations that can be applied to these objects. Semistructured, and
Unstructured Data
XML Hierarchical
I They are designed so they can be directly- or seamlessly - (Tree) Data Model
integrated with software that is developed using object-oriented
programming languages.

AAiT - School of Electrical and Computer Engineering 68


Introduction to Object-Oriented Concepts and Features
Chapter 2

An object typically has two components: state (value) and behavior Yonas Y.

(operations). It can have a complex data structure as well as specific Outline


operations defined by the programmer. The Relational Data
Model Concepts
Relational Model
Concepts
Relational Model
Constraints and
Relational Database
Schemas
Update Operations,
Transactions, and
Dealing with
Constraint Violations
Object and
Object-Relational
Databases
Overview of Object
Database Concepts
Extensible Markup
Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 69


Introduction to Object-Oriented Concepts and Features
Chapter 2

An object typically has two components: state (value) and behavior Yonas Y.

(operations). It can have a complex data structure as well as specific Outline


operations defined by the programmer. The Relational Data
Model Concepts
OO databases store persistent objects permanently in secondary Relational Model
Concepts
storage, and allow the sharing of these objects among multiple Relational Model
Constraints and
programs and applications. Relational Database
Schemas
An OO database system will typically interface with one or more OO Update Operations,
Transactions, and
programming languages to provide persistent and shared object Dealing with
Constraint Violations
capabilities. Object and
Object-Relational
Databases
Overview of Object
Database Concepts
Extensible Markup
Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 70


Introduction to Object-Oriented Concepts and Features
Chapter 2

An object typically has two components: state (value) and behavior Yonas Y.

(operations). It can have a complex data structure as well as specific Outline


operations defined by the programmer. The Relational Data
Model Concepts
OO databases store persistent objects permanently in secondary Relational Model
Concepts
storage, and allow the sharing of these objects among multiple Relational Model
Constraints and
programs and applications. Relational Database
Schemas
An OO database system will typically interface with one or more OO Update Operations,
Transactions, and
programming languages to provide persistent and shared object Dealing with
Constraint Violations
capabilities. Object and
Object-Relational
The internal structure of an object in OOPLs includes the specification Databases
Overview of Object
of instance variables, which hold the values that define the internal Database Concepts

state of the object. Extensible Markup


Language
Structured,
An instance variable is similar to the concept of an attribute in the Semistructured, and
Unstructured Data
relational model except that instance variables may be encapsulated XML Hierarchical
(Tree) Data Model
within the object and thus are not necessarily visible to external users.
Object-oriented systems allow definition of the operations or functions
(behavior) that can be applied to objects of a particular type.

AAiT - School of Electrical and Computer Engineering 71


Object Identity, and Objects versus Literals Chapter 2

Yonas Y.
ODMS (Object Data Management System) provides a unique identity
to each independent object stored in the database. This unique identity Outline

is typically implemented via a unique, system-generated object The Relational Data


Model Concepts
identifier (OID). Relational Model
Concepts
Relational Model
Constraints and
Relational Database
Schemas
Update Operations,
Transactions, and
Dealing with
Constraint Violations
Object and
Object-Relational
Databases
Overview of Object
Database Concepts
Extensible Markup
Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 72


Object Identity, and Objects versus Literals Chapter 2

Yonas Y.
ODMS (Object Data Management System) provides a unique identity
to each independent object stored in the database. This unique identity Outline

is typically implemented via a unique, system-generated object The Relational Data


Model Concepts
identifier (OID). Relational Model
Concepts
The value of an OID is not visible to the external user, but is used Relational Model
Constraints and
internally by the system to identify each object uniquely and to create Relational Database
Schemas
and manage inter-object references. Update Operations,
Transactions, and
Dealing with
Constraint Violations
Object and
Object-Relational
Databases
Overview of Object
Database Concepts
Extensible Markup
Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 73


Object Identity, and Objects versus Literals Chapter 2

Yonas Y.
ODMS (Object Data Management System) provides a unique identity
to each independent object stored in the database. This unique identity Outline

is typically implemented via a unique, system-generated object The Relational Data


Model Concepts
identifier (OID). Relational Model
Concepts
The value of an OID is not visible to the external user, but is used Relational Model
Constraints and
internally by the system to identify each object uniquely and to create Relational Database
Schemas
and manage inter-object references. Update Operations,
Transactions, and
Dealing with
The main property required of an OID is that it be immutable; that is, Constraint Violations

the OID value of a particular object should not change. It is also Object and
Object-Relational
desirable that each OID be used only once; that is, even if an object is Databases
Overview of Object
removed from the database, its OID should not be assigned to another Database Concepts

object. Extensible Markup


Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 74


Object Identity, and Objects versus Literals Chapter 2

Yonas Y.
ODMS (Object Data Management System) provides a unique identity
to each independent object stored in the database. This unique identity Outline

is typically implemented via a unique, system-generated object The Relational Data


Model Concepts
identifier (OID). Relational Model
Concepts
The value of an OID is not visible to the external user, but is used Relational Model
Constraints and
internally by the system to identify each object uniquely and to create Relational Database
Schemas
and manage inter-object references. Update Operations,
Transactions, and
Dealing with
The main property required of an OID is that it be immutable; that is, Constraint Violations

the OID value of a particular object should not change. It is also Object and
Object-Relational
desirable that each OID be used only once; that is, even if an object is Databases
Overview of Object
removed from the database, its OID should not be assigned to another Database Concepts

object. Extensible Markup


Language

Most OO database systems allow for the representation of both objects Structured,
Semistructured, and
Unstructured Data
and literals (or values). Every object must have an immutable OID, XML Hierarchical
whereas a literal value has no OID and its value just stands for itself. (Tree) Data Model

I Thus, a literal value is typically stored within an object and cannot


be referenced from other objects.

AAiT - School of Electrical and Computer Engineering 75


Complex Type Structures for Objects and Literals
Another feature of an ODMS (and ODBs in general) is that objects and Chapter 2
literals may have a type structure of arbitrary complexity in order to Yonas Y.
contain all of the necessary information that describes the object or
Outline
literal.
The Relational Data
Model Concepts
Relational Model
Concepts
Relational Model
Constraints and
Relational Database
Schemas
Update Operations,
Transactions, and
Dealing with
Constraint Violations
Object and
Object-Relational
Databases
Overview of Object
Database Concepts
Extensible Markup
Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 76


Complex Type Structures for Objects and Literals
Another feature of an ODMS (and ODBs in general) is that objects and Chapter 2
literals may have a type structure of arbitrary complexity in order to Yonas Y.
contain all of the necessary information that describes the object or
Outline
literal.
The Relational Data
In ODBs, a complex type may be constructed from other types by Model Concepts
Relational Model
nesting of type constructors. The three most basic constructors are: Concepts
Relational Model
1. One type constructor has been called the atom constructor. This Constraints and
Relational Database
includes the basic built-in data types of the object model, which Schemas
Update Operations,
are similar to the basic types in many programming languages: Transactions, and
Dealing with
integers, strings, floating point numbers, enumerated types, Constraint Violations

Booleans, and so on. Object and


Object-Relational
Databases
Overview of Object
Database Concepts
Extensible Markup
Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 77


Complex Type Structures for Objects and Literals
Another feature of an ODMS (and ODBs in general) is that objects and Chapter 2
literals may have a type structure of arbitrary complexity in order to Yonas Y.
contain all of the necessary information that describes the object or
Outline
literal.
The Relational Data
In ODBs, a complex type may be constructed from other types by Model Concepts
Relational Model
nesting of type constructors. The three most basic constructors are: Concepts
Relational Model
1. One type constructor has been called the atom constructor. This Constraints and
Relational Database
includes the basic built-in data types of the object model, which Schemas
Update Operations,
are similar to the basic types in many programming languages: Transactions, and
Dealing with
integers, strings, floating point numbers, enumerated types, Constraint Violations

Booleans, and so on. Object and


Object-Relational
Databases
2. A second type constructor is referred to as the struct (or tuple) Overview of Object
constructor. This can create standard structured types, such as Database Concepts
Extensible Markup
the tuples (record types) in the basic relational model. Language
For example: Structured,
Semistructured, and
I struct Name<FirstName: string, MiddleInitial: char, LastName: Unstructured Data
string>, XML Hierarchical
(Tree) Data Model
I struct CollegeDegree<Major: string, Degree: string, Year: date>.

AAiT - School of Electrical and Computer Engineering 78


Complex Type Structures for Objects and Literals
Another feature of an ODMS (and ODBs in general) is that objects and Chapter 2
literals may have a type structure of arbitrary complexity in order to Yonas Y.
contain all of the necessary information that describes the object or
Outline
literal.
The Relational Data
In ODBs, a complex type may be constructed from other types by Model Concepts
Relational Model
nesting of type constructors. The three most basic constructors are: Concepts
Relational Model
1. One type constructor has been called the atom constructor. This Constraints and
Relational Database
includes the basic built-in data types of the object model, which Schemas
Update Operations,
are similar to the basic types in many programming languages: Transactions, and
Dealing with
integers, strings, floating point numbers, enumerated types, Constraint Violations

Booleans, and so on. Object and


Object-Relational
Databases
2. A second type constructor is referred to as the struct (or tuple) Overview of Object
constructor. This can create standard structured types, such as Database Concepts
Extensible Markup
the tuples (record types) in the basic relational model. Language
For example: Structured,
Semistructured, and
I struct Name<FirstName: string, MiddleInitial: char, LastName: Unstructured Data
string>, XML Hierarchical
(Tree) Data Model
I struct CollegeDegree<Major: string, Degree: string, Year: date>.
3. Collection (or multivalued) type constructors include the set(T),
list(T), bag(T), array(T), and dictionary(K,T) type constructors.
These allow part of an object or literal value to include a collection
of other objects or values when needed.
AAiT - School of Electrical and Computer Engineering 79
The main characteristic of a collection type is that its objects or values
will be a collection of objects or values of the same type that may be
unordered (such as a set or a bag) or ordered (such as a list or an array). Chapter 2

Yonas Y.
An object definition language (ODL) that incorporates the preceding
type constructors can be used to define the object types for a particular Outline

database application. The Relational Data


Model Concepts
Relational Model
Concepts
Relational Model
Constraints and
Relational Database
Schemas
Update Operations,
Transactions, and
Dealing with
Constraint Violations
Object and
Object-Relational
Databases
Overview of Object
Database Concepts
Extensible Markup
Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 80


The main characteristic of a collection type is that its objects or values
will be a collection of objects or values of the same type that may be
unordered (such as a set or a bag) or ordered (such as a list or an array). Chapter 2

Yonas Y.
An object definition language (ODL) that incorporates the preceding
type constructors can be used to define the object types for a particular Outline

database application. The Relational Data


Model Concepts
The following ODL code shows how we may declare EMPLOYEE and Relational Model
Concepts
DEPARTMENT types in ODMS. Relational Model
Constraints and
Relational Database
Schemas
define type EMPLOYEE Update Operations,
tuple ( Name: string; Transactions, and
Dealing with
Constraint Violations
Fname: string;
Object and
TinNo: string; Object-Relational
Databases
Birth date: DATE; Overview of Object
Address: string; Database Concepts
Extensible Markup
Sex: char; Language
Salary: float; Structured,
Semistructured, and
Supervisor: EMPLOYEE; Unstructured Data
XML Hierarchical
Dept: DEPARTMENT; (Tree) Data Model

define type DATE


tuple ( Year: integer;
Month: integer;
Date: integer;
AAiT - School of Electrical and Computer Engineering 81
Chapter 2

Yonas Y.

Outline

The Relational Data


Model Concepts
define type DEPARTMENT Relational Model
Concepts
tuple ( DName: string; Relational Model
Constraints and
Dnumber: integer; Relational Database
Schemas
Mgr: tuple ( Manager: EMPLOYEE; Update Operations,
Transactions, and
Start date: DATE;); Dealing with
Constraint Violations
Locations: set(string);
Object and
Employees: set(EMPLOYEE); Object-Relational
Databases
Projects: set(PROJECT);); Overview of Object
Database Concepts
Extensible Markup
Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 82


Extensible Markup Language
Chapter 2

Yonas Y.

Outline

The Relational Data


E-commerce and other Internet database applications are designed to Model Concepts
Relational Model
interact with the user through Web interfaces that display Web pages. Concepts
Relational Model
Constraints and
The common method of specifying the contents and formatting of Web Relational Database
Schemas
pages is through the use of hypertext documents. There are various Update Operations,
Transactions, and
languages for writing these documents, the most common being HTML Dealing with
Constraint Violations
(HyperText Markup Language).
Object and
Object-Relational
Databases
Overview of Object
Database Concepts
Extensible Markup
Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 83


Extensible Markup Language
Chapter 2

Yonas Y.

Outline

The Relational Data


E-commerce and other Internet database applications are designed to Model Concepts
Relational Model
interact with the user through Web interfaces that display Web pages. Concepts
Relational Model
Constraints and
The common method of specifying the contents and formatting of Web Relational Database
Schemas
pages is through the use of hypertext documents. There are various Update Operations,
Transactions, and
languages for writing these documents, the most common being HTML Dealing with
Constraint Violations
(HyperText Markup Language).
Object and
Object-Relational
This days, XML (Extensible Markup Language) - has emerged as the Databases

standard for structuring and exchanging data over the Web. Overview of Object
Database Concepts
XML can be used to provide information about the structure and Extensible Markup
Language
meaning of the data in the Web pages rather than just specifying how Structured,
the Web pages are formatted for display on the screen. Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 84


Structured, Semistructured, and Unstructured Data
Chapter 2
The information stored in databases is known as structured data Yonas Y.
because it is represented in a strict format. For structured data, the
Outline
DBMS checks to ensure that all data follows the structures and
The Relational Data
constraints specified in the schema. Model Concepts
Relational Model
Concepts
Relational Model
Constraints and
Relational Database
Schemas
Update Operations,
Transactions, and
Dealing with
Constraint Violations
Object and
Object-Relational
Databases
Overview of Object
Database Concepts
Extensible Markup
Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 85


Structured, Semistructured, and Unstructured Data
Chapter 2
The information stored in databases is known as structured data Yonas Y.
because it is represented in a strict format. For structured data, the
Outline
DBMS checks to ensure that all data follows the structures and
The Relational Data
constraints specified in the schema. Model Concepts
Relational Model
In some applications, data is collected in an ad hoc manner before it is Concepts
Relational Model
known how it will be stored and managed. This data may have a Constraints and
Relational Database
certain structure, but not all the information collected will have the Schemas
Update Operations,
identical structure. This type of data is known as semistructured data. Transactions, and
Dealing with
Constraint Violations
In semistructured data, the schema information is mixed in with the
Object and
data values, since each data object can have different attributes that are Object-Relational
Databases
not known in advance. Hence, this type of data is sometimes referred to Overview of Object
as self-describing data. Database Concepts
Extensible Markup
Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 86


Structured, Semistructured, and Unstructured Data
Chapter 2
The information stored in databases is known as structured data Yonas Y.
because it is represented in a strict format. For structured data, the
Outline
DBMS checks to ensure that all data follows the structures and
The Relational Data
constraints specified in the schema. Model Concepts
Relational Model
In some applications, data is collected in an ad hoc manner before it is Concepts
Relational Model
known how it will be stored and managed. This data may have a Constraints and
Relational Database
certain structure, but not all the information collected will have the Schemas
Update Operations,
identical structure. This type of data is known as semistructured data. Transactions, and
Dealing with
Constraint Violations
In semistructured data, the schema information is mixed in with the
Object and
data values, since each data object can have different attributes that are Object-Relational
Databases
not known in advance. Hence, this type of data is sometimes referred to Overview of Object
as self-describing data. Database Concepts
Extensible Markup
I Example: Language
Structured,
We want to collect a list of bibliographic references related to a Semistructured, and
Unstructured Data
certain research project. Some of these may be books or technical XML Hierarchical
(Tree) Data Model
reports, others may be research articles in journals or conference
proceedings, and still others may refer to complete journal issues or
conference proceedings. Such example represents a semistructured
data database.

AAiT - School of Electrical and Computer Engineering 87


Semistructured data may be displayed as a directed graph, as shown in
Figure 2.3.
Chapter 2

Yonas Y.

Outline

The Relational Data


Model Concepts
Relational Model
Concepts
Relational Model
Constraints and
Relational Database
Schemas
Update Operations,
Transactions, and
Dealing with
Constraint Violations
Object and
Object-Relational
Databases
Overview of Object
Database Concepts
Extensible Markup
Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

Figure: 2.3 Representing semistructured data as a graph.


AAiT - School of Electrical and Computer Engineering 88
Chapter 2

Yonas Y.

Outline
I The labels or tags on the directed edges represent the schema
The Relational Data
names: the names of attributes, object types (or entity types or Model Concepts
classes), and relationships. Relational Model
Concepts
Relational Model
I The internal nodes represent individual objects or composite Constraints and
Relational Database
attributes. Schemas
Update Operations,
I The leaf nodes represent actual data values of simple (atomic) Transactions, and
Dealing with
Constraint Violations
attributes.
Object and
Object-Relational
Databases
Overview of Object
Database Concepts
Extensible Markup
Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 89


Chapter 2

Yonas Y.

Outline
I The labels or tags on the directed edges represent the schema
The Relational Data
names: the names of attributes, object types (or entity types or Model Concepts
classes), and relationships. Relational Model
Concepts
Relational Model
I The internal nodes represent individual objects or composite Constraints and
Relational Database
attributes. Schemas
Update Operations,
I The leaf nodes represent actual data values of simple (atomic) Transactions, and
Dealing with
Constraint Violations
attributes.
Object and
Object-Relational
Databases
In addition to structured and semistructured data, a third category Overview of Object
Database Concepts
exists, known as unstructured data because there is very limited Extensible Markup
indication of the type of data. A typical example is a text document Language
Structured,
that contains information embedded within it. Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 90


XML Hierarchical (Tree) Data Model
Chapter 2
The basic object in XML is the XML document. Two main structuring
Yonas Y.
concepts are used to construct an XML document: elements and
attributes. Outline

Attributes in XML provide additional information that describes The Relational Data
Model Concepts
elements. Figure 2.4 shows an example of an XML element called Relational Model
Concepts
<Projects>. Relational Model
Constraints and
Relational Database
Schemas
Update Operations,
Transactions, and
Dealing with
Constraint Violations
Object and
Object-Relational
Databases
Overview of Object
Database Concepts
Extensible Markup
Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 91


Chapter 2

Yonas Y.

Outline

The Relational Data


Model Concepts
Relational Model
Concepts
Relational Model
Constraints and
Relational Database
Schemas
Update Operations,
Transactions, and
Dealing with
Constraint Violations
Object and
Object-Relational
Databases
Figure: 2.4 A complex XML element called <Projects>. Overview of Object
Database Concepts
Extensible Markup
Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 92


Chapter 2

Yonas Y.

Outline

The Relational Data


Model Concepts
Relational Model
Concepts
Relational Model
Constraints and
Relational Database
Schemas
Update Operations,
Transactions, and
Dealing with
Constraint Violations
Object and
Object-Relational
Databases
Figure: 2.4 A complex XML element called <Projects>. Overview of Object
Database Concepts
Extensible Markup
Complex elements are constructed from other elements hierarchically, Language
whereas simple elements contain data values. Structured,
Semistructured, and
Unstructured Data
I In Figure 2.4, the simple elements are the ones with the tag names XML Hierarchical
(Tree) Data Model
< Name >, < Number >, < Location >, < Dept no >, < Ssn >
, < Last name >, < First name >, and < Hours >.
I The complex elements are the ones with the tag names
< Projects >, < Project >, and < Worker >. In general, there is
no limit on the levels of nesting of elements.
AAiT - School of Electrical and Computer Engineering 93
Chapter 2
It is possible to characterize three main types of XML documents:
Yonas Y.
I Data-centric XML documents. These documents have many
Outline
small data items that follow a specific structure and hence may be
The Relational Data
extracted from a structured database. They are formatted as XML Model Concepts
documents in order to exchange them over or display them on the Relational Model
Concepts
Web. These usually follow a predefined schema that defines the Relational Model
Constraints and
tag names. Relational Database
Schemas
Update Operations,
Transactions, and
Dealing with
Constraint Violations
Object and
Object-Relational
Databases
Overview of Object
Database Concepts
Extensible Markup
Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 94


Chapter 2
It is possible to characterize three main types of XML documents:
Yonas Y.
I Data-centric XML documents. These documents have many
Outline
small data items that follow a specific structure and hence may be
The Relational Data
extracted from a structured database. They are formatted as XML Model Concepts
documents in order to exchange them over or display them on the Relational Model
Concepts
Web. These usually follow a predefined schema that defines the Relational Model
Constraints and
tag names. Relational Database
Schemas
Update Operations,
I Document-centric XML documents. These are documents with Transactions, and
Dealing with
large amounts of text, such as news articles or books. There are Constraint Violations

few or no structured data elements in these documents. Object and


Object-Relational
Databases
Overview of Object
Database Concepts
Extensible Markup
Language
Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 95


Chapter 2
It is possible to characterize three main types of XML documents:
Yonas Y.
I Data-centric XML documents. These documents have many
Outline
small data items that follow a specific structure and hence may be
The Relational Data
extracted from a structured database. They are formatted as XML Model Concepts
documents in order to exchange them over or display them on the Relational Model
Concepts
Web. These usually follow a predefined schema that defines the Relational Model
Constraints and
tag names. Relational Database
Schemas
Update Operations,
I Document-centric XML documents. These are documents with Transactions, and
Dealing with
large amounts of text, such as news articles or books. There are Constraint Violations

few or no structured data elements in these documents. Object and


Object-Relational
Databases
I Hybrid XML documents. These documents may have parts that Overview of Object
contain structured data and other parts that are predominantly Database Concepts
Extensible Markup
textual or unstructured. They may or may not have a predefined Language
schema. Structured,
Semistructured, and
Unstructured Data
XML Hierarchical
(Tree) Data Model

AAiT - School of Electrical and Computer Engineering 96


Chapter 2
It is possible to characterize three main types of XML documents:
Yonas Y.
I Data-centric XML documents. These documents have many
Outline
small data items that follow a specific structure and hence may be
The Relational Data
extracted from a structured database. They are formatted as XML Model Concepts
documents in order to exchange them over or display them on the Relational Model
Concepts
Web. These usually follow a predefined schema that defines the Relational Model
Constraints and
tag names. Relational Database
Schemas
Update Operations,
I Document-centric XML documents. These are documents with Transactions, and
Dealing with
large amounts of text, such as news articles or books. There are Constraint Violations

few or no structured data elements in these documents. Object and


Object-Relational
Databases
I Hybrid XML documents. These documents may have parts that Overview of Object
contain structured data and other parts that are predominantly Database Concepts
Extensible Markup
textual or unstructured. They may or may not have a predefined Language
schema. Structured,
Semistructured, and
Unstructured Data
XML documents that do not follow a predefined schema of element XML Hierarchical
(Tree) Data Model
names and corresponding tree structure are known as schemaless XML
documents.

AAiT - School of Electrical and Computer Engineering 97

You might also like