0% found this document useful (0 votes)
40 views21 pages

W3. The Relational Model

The relational model represents data as mathematical relations, or tables, with rows and columns. A relation has a name and attributes that define the columns. The rows are called tuples. Relations have keys like primary and foreign keys that define relationships between tables. Views allow querying relations in customized ways without changing the base relations. Integrity constraints like entity and referential integrity ensure data consistency.

Uploaded by

SABOOR UR RAHMAN
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views21 pages

W3. The Relational Model

The relational model represents data as mathematical relations, or tables, with rows and columns. A relation has a name and attributes that define the columns. The rows are called tuples. Relations have keys like primary and foreign keys that define relationships between tables. Views allow querying relations in customized ways without changing the base relations. Integrity constraints like entity and referential integrity ensure data consistency.

Uploaded by

SABOOR UR RAHMAN
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 21

Database Management System

The Relational Model

Dr. Abdul Ahad Abro

Content taken from: © Pearson Education Limited 1995, 2005


Objectives
To learn:
•The origins of the relational model.
•The terminology of the relational model.
•How tables are used to represent data.
•The connection between mathematical relations and relations in the relational
•model.
•Properties of database relations.
•How to identify candidate, primary, alternate, and foreign keys.
•The meaning of entity integrity and referential integrity.
•The purpose and advantages of views in relational systems
Relational Model Terminology
• A relation is a table with columns and rows.
– Only applies to logical structure of the database, not the physical
structure.

• Each relation has a name and is made up of named attributes (columns) of


data. Each tuple (row) contains one value per attribute.
Relational Model Terminology
The relational model is based on the mathematical concept of a relation, which is
physically represented as a table.

•A relation is a table with columns and rows


•Tuple is a row of a relation.
•An attribute is a named column of a relation
•Degree is the number of attributes in a relation.
•Cardinality is the number of tuples in a relation.
•A domain is the set of allowable values for one or more attributes.
•Relational Database is a collection of normalized relations with distinct relation
names.
Instances of Branch and Staff Relations
Examples of Attribute Domains
Alternative Terminology for Relational Model
Database Relations
• Consider two sets, D1 & D2,
where D1 = {2, 4} and D2 = {1, 3, 5}.
• Cartesian product, D1 ´ D2, is set of all ordered pairs, where first element is
member of D1 and second element is member of D2.

D1 ´ D2 = {(2, 1), (2, 3), (2, 5), (4, 1), (4, 3), (4, 5)}

• Alternative way is to find all combinations of elements with first from D1 and
second from D2.
Database Relations
Mathematical Definition of Relation
Any subset of Cartesian product is a relation.
e.g.
R = {(2, 1), (4, 1)}
•May specify which pairs are in relation using some condition for selection;
e.g.
– second element is 1:
R = {(x, y) | x ÎD1, y ÎD2, and y = 1}
– first element is always twice the second:
S = {(x, y) | x ÎD1, y ÎD2, and x = 2y}
Database Relations
• Consider three sets D1, D2, D3 with Cartesian Product D1 ´ D2 ´ D3;
e.g.

D1 = {1, 3} D2 = {2, 4} D3 = {5, 6}


D1 ´ D2 ´ D3 = {(1,2,5), (1,2,6), (1,4,5), (1,4,6), (3,2,5), (3,2,6), (3,4,5), (3,4,6)}

• Any subset of these ordered triples is a relation.


Database Relations
• Cartesian product of n sets (D1, D2, . . ., Dn) is:

D1 ´ D2 ´ . . . ´ Dn = {(d1, d2, . . . , dn) | d1 ÎD1, d2 ÎD2, . . . , dnÎDn}


usually written as:
n
XD
i = 1
i

• Any set of n-tuples from this Cartesian product is a relation on the n sets.
Database Relations
Relation schema
Named relation defined by a set of attribute and domain name pairs.
• Let A1, A2, . . . , An be attributes with domains D1, D2, . . . , Dn. Then the
set {A1:D1, A2:D2,. . . , An:Dn} is a relation schema.
• A relation R defined by a relation schema S is a set of mappings from the
attribute names to their corresponding domains. Thus, relation R is a set
of n-tuples:
• A table is simply a physical representation of such a relation.
Database Relations
Relational database schema
Set of relation schemas, each with a distinct name.

• If R1, R2, . . . , Rn are a set of relation schemas, then we can write the
relational database schema, or simply relational schema, R, as:
Properties of Relations
• Relation name is distinct from all other relation names in relational schema.
• Each cell of relation contains exactly one atomic (single) value.
• Each attribute has a distinct name.
• Values of an attribute are all from the same domain.
• Each tuple is distinct; there are no duplicate tuples.
• Order of attributes has no significance.
• Order of tuples has no significance, theoretically.
Relational Keys
Superkey
• An attribute, or set of attributes, that uniquely identifies a tuple within a
relation.

Candidate Key
• Superkey (K) such that no proper subset is a superkey within the relation.
• In each tuple of R, values of K uniquely identify that tuple (uniqueness).
• No proper subset of K has the uniqueness property (irreducibility).
Relational Keys
Primary Key
• Candidate key selected to identify tuples uniquely within relation.

Alternate Keys
• Candidate keys that are not selected to be primary key.

Foreign Key
• Attribute, or set of attributes, within one relation that matches candidate
key of some relation.
Integrity Constraints
Null
• Represents value for an attribute that is currently unknown or not applicable
for tuple.
• Deals with incomplete or exceptional data.
• Represents the absence of a value and is not the same as zero or spaces,
which are values.
Integrity Constraints
Entity Integrity
• In a base relation, no attribute of a primary key can be null.

Referential Integrity
• If foreign key exists in a relation, either foreign key value must match a
candidate key value of some tuple in its home relation or foreign key value
must be wholly null.

General Constraints
• Additional rules specified by users or database administrators that define or
constrain some aspect of the enterprise.
Views
Base Relation
A named relation corresponding to an entity in the conceptual schema, whose
tuples are physically stored in the database

View
The dynamic result of one or more relational operations operating on the base
relations to produce another relation. A view is a virtual relation that does not
necessarily exist in the database but can be produced upon request by a particular
user, at the time of request.
Views
Properties
•Views are dynamic
•A view is a virtual or derived relation
•Does not necessarily exist in storage
•The contents of a view are defined as a query

Purpose
•It provides a powerful and flexible security mechanism by hiding parts of the
database from certain users.
•It permits users to access data in a way that is customized to their needs
•It can simplify complex operations on the base relations.
Updating Views
•Updates are allowed through a view defined using a simple query involving a
single base relation and containing either the primary key or a candidate key of
the base relation.
• Updates are not allowed through views involving multiple base relations.
•Updates are not allowed through views involving aggregation or grouping
operations

You might also like