Sie sind auf Seite 1von 30

THE RELATIONAL

MODEL
BCA20
Engr. Florence B. Reyes
DATA MODELS
 A Database models
some portion of the real
world.

 Data Model is link


between user’s view of
the world and bits
Student (sid: string, name: string, login:
stored in computer. string, age: integer, gpa:real)

 Many models have been


proposed.
10101
 We will concentrate on
11101
the Relational Model.
DESCRIBING DATA: DATA MODELS
A data model is a collection of concepts for
describing data.

A database schema is a description of a


particular collection of data, using a given
data model.

 Therelational model of data is the most


widely used model today.
 Main concept: relation, basically a table with
rows and columns.
 Every relation has a schema, which describes the
columns, or fields.
LEVELS OF ABSTRACTION
Users
 Views describe how
users see the data.

 Conceptual schema
defines logical View 1 View 2 View 3
structure

Conceptual Schema
 Physical schema
describes the files
and indexes used. Physical Schema

DB
LEVELS OF ABSTRACTION

External view 1 External view 2


Staff_no FName LName Age Salary Staff_no LName Branch_no

Conceptual Level Staff_no FName LName DOB Salary Branch_no

struct STAFF {
int Staff_no;
int Branch_no;
Physical Level char FName[15];
char LName[15];
struct date DOB;
float Salary;
struct STAFF *next;
};
index Staff_no; index Branch_no;
DATA INDEPENDENCE: THE BIG
BREAKTHROUGH OF THE RELATIONAL MODEL
 A Simple Idea:
Applications should be
insulated from how data is View 1 View 2 View 3
structured and stored.

Logical data

independence: Protection Conceptual Schema
from changes in logical
structure of data.
Physical Schema
 Physical data
independence: Protection
from changes in physical
structure of data.
DB
 Q: Why are these
particularly important for
DBMS?
RELATIONAL DATA MODEL CONCEPTS
 Therelational Model of Data is based on the
concept of a Relation, which is physically
represented as a table.

A Relation is a mathematical concept based


on the ideas of sets.

 Themodel was first proposed by Dr. E.F.


Codd of IBM in 1970 in the following paper:
"A Relational Model for Large Shared Data
Banks," Communications of the ACM, June
1970.
RELATIONAL DATABASES
 A relational database is a collection of
relations.
 A relation is a two-dimensional table in
which:
 The entries in the table are single-valued; that is,
each location in the table contains a single value.
 Each column has a distinct name (technically called
the attribute name).
 All values in a column are values of the same
attribute (that is, all entries must much the column
name).
 The order of columns is immaterial.
 Each row is distinct.
 The order of rows is immaterial.
RELATIONAL DATABASES
 Unnormalized relation is a table (relation)
wherein a structure satisfies all the
properties of a relation except some of the
entries contain repeating groups and thus are
not single-valued.

 Rows in a table (relation) are often called


records or tuples.
 Columns in a table (relation) are often called
fields or attributes.
TABLES AND RELATION
 The term Table is used interchangeably with Relation
– Every relation is a table
– Every table is not necessarily a relation !
City: Brisbane Year: 1998
Product
Region Suburb Qtr 1 Qtr 2 Qtr 3 Qtr 4
South Algeter Disk 32 243 23 246
South Calam Vale Labels 4232 65 865 768

West Taringa Envelops 3242 543 4554 454


Not a
Relation !
North McDowell Toners 23 465 24 432

South Sunny Bank Ribbons 324 65 56 657

West Indooroopilly Disk 234 6786 324


RELATION COMPONENTS
Relation
Name
Attribute Names

STUDENT
Name StudentNo Sex Degree

Joe Smith 606 567 333 M BSc

A. Brown 321 638 999 F BInfTch

Tuples

Attribute Values
from same Domain
DOMAINS
 A Domain D is the set of allowable values for one
or more attributes
 is a set of atomic values
 An atomic value is indivisible (as far as the
relational data model is concerned)
 Each domain has a data type or format
 Examples:
– Domain of Names:
{Joe Smith, Alan Yates, Bob Lovell, Jane
Austin, ...}
– Domain of Degrees:
{Phd, MSc, BInfTech, BSc, MInfTech, …}
DOMAIN TYPES
 integers
 real numbers
 fixed or variable length character strings
 date
 time stamp
 currency
 sub-range from a data type, e.g. 1£_ Grade £_ 7
 enumerated data type, e.g. {‘Male’, ‘Female’}
EXAMPLE DOMAINS
Indonesian telephone numbers
 Values: the set of telephone numbers valid in
Indonesia
 Format: the digits “62” followed by 9 digits 0-9

Auto registration numbers


 Values: The set of valid vehicle registration codes
(i.e., arbitrary combinations of characters and
digits)
 Format: 6 characters (either alpha or digits but
no ‘Q’s allowed)
ATTRIBUTES
 An attribute is a named column of a relation.
 Each attribute A is the name of a role played by
some domain D in the relation named R

 Example: StudentNo is an attribute name

Name StudentNo Sex Degree


Joe Smith 606 567 333 M BSc
A. Brown 321 638 999 F BInfTch
DOMAINS / ATTRIBUTES RESTRICTIONS
 Same attribute name does not necessarily imply same
domain

Subject Lecturer
Code Subject Code Staffmem
CSEE CS182 CS182 Harrison
CSEF CS180 CS181 Duke
Law LA303 CS180 Marjanovic

Domains for Subject.CODE and Lecturer.CODE must


differ, even though Attribute names are the same
DOMAINS / ATTRIBUTES RESTRICTIONS

 Differentattribute name does not


necessarily imply different domain

EID ENAME ESAL EADDR SID


86 Smith $42K Fry Ave 52
52 Chen $54K King St. 52
Domains for EID and SID are the same
but the Attribute names must differ
TUPLES
A tuple is a row of a relation.

 Each Tuple t is an ordered list of n values: t =


<v1,v2, … , vn> where each value vi (1 £ i £ n)
is an element of the corresponding domain of
attribute Ai or a special value called “null”
 t is called an n-tuple
 Example
(254, John, Smith, $45K, 3453-2543,M)
TUPLES
A tuple is an ordered set of values
 Each value is derived from an appropriate
domain.
 Each row in the CUSTOMER table may be
referred to as a tuple in the table and would
consist of four values.
 <632895, "John Smith", "101 Main St. Atlanta,
GA 30332", "(404) 894-2000">
is a tuple belonging to the CUSTOMER relation.
 A relation may be regarded as a set of tuples
(rows).
 Columns in a table are also called attributes of
the relation.
DEGREE
 The degree of a relation is the number of
attributes it contains.
 The number of attributes in a relation R is
called the degree of R
degree of R (4)

Name StudentNo Sex Degree


Joe Smith 606 567 M BSc
333
A. Brown 321 638 F BInfTch
999
CARDINALITY
 The
cardinality of a relation is the
number of tuples it contains.

 Cardinality of R (2)

Name StudentNo Sex Degree


Joe Smith 606 567 M BSc
333 Cardinality
A. Brown 321 638 F BInfTch
999
RELATION COMPONENTS - REVIEW
Relation
Name
Attribute Names

STUDENT

Name StudentNo Sex Degree


Joe Smith 606 567 333 M BSc
A. Brown 321 638 999 F BInfTch
Tuples

Attribute Values
from same Domain
DEFINITION SUMMARY

Informal Terms Formal Terms

Table Relation
Column/Field Attribute
Row/Record Tuple
Values in a column Domain
Table Definition Schema of Relation
No. of Columns Degree of Relation
No. of Rows Cardinality of Relation
EXAMPLE
RELATION SCHEMA AND INSTANCE
 RelationSchema
– Denoted by R(A1,A2,A3,…,An), includes a
relation
name R and list of attributes A1, A2, … An
– Integer n is termed “degree of the relation”
– Example relation schema of degree 4:
STUDENT(Name, Age, Id, Address)

 RelationInstance
– A relation instance r of the relation schema R,
denoted by r(R), is a set of n-tuples r = {t1,t2,
…,
tm}.
EXAMPLE OF SCHEMA AND INSTANCE

Schema: description of the relation

Name StudentNo Sex Degree


Joe Smith 606 567 333 M BSc
A. Brown 321 638 999 F BInfTch

Instance: data within the relation


PROPERTIES OF RELATIONS
A relation has the following characteristics:
 The relation name has a name that is distinct
from all other relations
 Each cell of the relation contains exactly one
atomic (single) value
 Each attribute has a distinct name
 The values of an attribute are all from the same
domain
 The order of attributes has no significance
 Each tuple is distinct; there are no duplicate
tuples
 The order of tuples has no significance,
theoritically.
EXERCISE:
Consider the following relation for a database, answer the
questions on the next silde.

PART
QUESTIONS:

1. What is the relation name?


2. Identify one attribute of the given
relation.
3. What is the degree of relation
given?
4. What is the cardinality of the
relation given?
5. Give a sample domain from the
field Class.

Das könnte Ihnen auch gefallen