Anda di halaman 1dari 33

Basics of Relational Model

Relational Model Concepts


The relational Model of Data is based on the

concept of a Relation.

A Relation is a mathematical concept based on

the ideas of sets.

The strength of the relational approach to data

management comes
foundation provided
relations.

from the formal


by the theory of

Chapter 5-2

INFORMAL DEFINITIONS
RELATION: A table of values

A relation may be thought of as a set of rows.


A relation may alternately be though of as a set of columns.
Each row represents a fact that corresponds to a real-world
entity or relationship.
Each row has a value of an item or set of items that uniquely
identifies that row in the table.
Each column typically is called by its column name or column
header or attribute name.

Chapter 5-3

FORMAL DEFINITIONS
A Relation may be defined in multiple ways.
The Schema of a Relation: R (A1, A2, .....An)

Relation schema R is defined over attributes A1,


A2, .....An
For Example CUSTOMER (Cust-id, Cust-name, Address, Phone#)
Here, CUSTOMER is a relation defined over the four
attributes Cust-id, Cust-name, Address, Phone#, each of
which has a domain or a set of valid values. For
example, the domain of Cust-id is 6 digit numbers.

Chapter 5-4

Example of a Relation

A relational Model is concerned with 3 components:

Data Structure
Data Integrity
Data Manipulation

Attribute:

An attribute is a named column of a relation.


A relation is represented as a two dimensional table in which
the rows of the table correspond to individual records and the
table columns correspond to attributes.
Attributes can appear in any order and the relation will be the
same relation and therefore covey the same meaning.

Tuple
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) 8942000">

is a tuple belonging to the CUSTOMER relation.


A relation may be regarded as a set of tuples (rows).

Chapter 5-8

Example - Figure

5.1

Chapter 5-9

Domain
Is the set of allowed values for one or more

attributes.
Defines the kind of data represented by the attribute.
Example: If a college has 5000 students then the
domain of Roll number may be from 1001 to 6000.

Domain
Each attribute in the model should be assigned

domain information that includes:

Data type
Length
Date Format
Range
Constraints
Null Support
Default value

Domain
A

domain
has
a
logical
definition:
e.g.,
USA_phone_numbers are the set of 10 digit phone
numbers valid in the U.S.

A domain may have a data-type or a format defined for it.

The USA_phone_numbers may have a format: (ddd)ddd-dddd where each d is a decimal digit. E.g., Dates have
various formats such as monthname, date, year or yyyymm-dd, or dd mm,yyyy etc.

An attribute designates the role played by the domain.

E.g., the domain Date may be used to define attributes


Invoice-date and Payment-date.

Chapter 5-12

Tuple
Extension
Intension
Degree
Cardinality

Schemas versus Instances


Schema Diagram: A diagrammatic display

of (some aspects of) a database schema.


Schema Construct: A component of the
schema or an object within the schema, e.g.,
STUDENT, COURSE.

Slide 2-14

Chapte
r 5-15

DEFINITION SUMMARY
Informal Terms

Formal Terms

Table
Column
Row
Values in a column
Table Definition
Populated Table

Relation
Attribute/Domain
Tuple
Domain
Schema of a Relation
Extension

Relational Keys
There should not be any duplicate tuple within a

relation.
Therefore we should identify one or more
attributes(called relational keys) that uniquely
identify each tuple in a relation.

Types of Keys

Super Key
Candidate Key
Primary Key
Alternate Key
Artificial Key

There is one more key, which is very imp. But it does

not hold the property of uniqueness and it is known


as Foreign Key.

Super Key
Are those attributes of a relation, which have the

properties of uniqueness.
Let us consider a relation R, by definition ,the set of
all attributes of R has the uniqueness property ,
meaning that, at any given time, no two tuples of
relation R are duplicates of one another.
Let K be a set of attributes of relation R.
Then K is a super key for R if and only if it posses
uniqueness.

Example
R=Student(Roll no., Name, Class)
Roll No.
Roll No.,Name
Roll No.,Class
Roll No.,Class,Name

Candidate Key
Are those attributes of a relation, which have the

properties of uniqueness and irreducibility.


Let K be a set of attributes of Relation R. Then K is a
candidate key for R if and only if it possesses both
properties:

Uniqueness
Irreducibility: No proper subset of K has the uniqueness
property.

Every relation has atleast one candidate key.


Example (Name,Class) is unique then it can be

identified as the candidate key if and only if Name


and class individually are nor unique.
IS (Roll No, Class) is a candidate key?

There can be any number of candidate keys in a

relation and no component of candidate key is


allowed to be null.

Primary Key
It has three properties:

Uniqueness
Irreducibility
Not Null

A relation has only one primary key. It may be a

single attribute or a combination of attributes.

Example
Student (Roll NO.,Name,Class,Mobile No.)
Identify candidate keys and a primary key.

Properties
Stable- The value of Primary Key must not change or

should not be null throughout the life of an entity.


Example: Age
Minimal: Should be composed of the minimum
number of fields that ensures the occurrences are
unique.

Definitive: A value must exist for every record at

creation time.
Accessible: anyone who wants to create , read and
delete a record must be able to see the primary key
value.

Identify the Primary Key


Emp ID

Project ID

Hours_worked

01

01

200

01

02

120

02

01

50

02

03

120

03

03

100

03

04

200

Alternate Keys
Candidate keys which are not chosen or promoted as

the primary key by the database designer, are known


as Alternate Keys.
Student(Roll No., Name, Class, Mobile No.).
Identify candidate , primary and alternate
keys.

Artificial Keys
An artificial key is the one that has no meaning to

the business or organization and performs the


function of primary key in a relation.

Artificial Keys are permitted when


No attributes has the primary key properties or the primary
key is large and complex.

Foreign Keys
Are the attributes of a table, which refers to the

primary key of some other table.


Foreign Keys permit only those values, which appear
in the primary key of the table to which it refers and
may be null.
The foreign key is a reference to the tuple of a table
from which it is taken ,this tuple being called the
Referenced table .

Foreign Key
EMP
Emp No.

Ename

jOB

Sal

Dept NO

Clerk

4000

10

Clerk

4000

20

Mgr

8000

20

Peon

2000

40

Clerk

4000

10

Mgr

8000

50

Target
Attribute
or
Primary
Key

Dept No.

Dname

Loc

10

asr

20

Jal

30

Qadian

40

Dept
Or
Targe
t
Table

Referential Integrity
Foreign key values should always be matched by

corresponding primary keys.

Referential Integrity
Entity Integrity
Enterprise Constraints

Anda mungkin juga menyukai