PPT - Ajay Ardeshana

advertisement
: Chapter – 2 :
Relational Data
Model
Introduction




Relational data model allows various data
packets/files to be related to each other with a set of
relations.
For example, if customer names are stored in one
file ‘CUSTOMER’, and other file contains the names
of cities ‘CITY’. Then CUSTOMER file can have a
relation with CITY, which will help identify which
city the customer belongs to.
The data is arranged in a relation which is visually
represented in a two dimensional table.
The data is inserted into the table in the form of
tuples (which are nothing but rows).
Count….
Introduction



(Count…)
A tuple is formed by one or more than one
attributes, which are used as basic building blocks in
the formation of various expressions that are used
to derive a meaningful information.
There can be any number of tuples in the table, but
all the tuple contain fixed and same attributes with
varying values.
The relational model is implemented in database
where a relation is represented by a table, a tuple is
represented by a row, an attribute is represented by
a column of the table, attribute name is the name of
the column.
Count…
Introduction


(Count…)
All the relational algebra operations, such as Select,
Intersection, Product, Union, Difference, Project,
Join, Division, Merge etc. can also be performed on
the Relational Database Model.
Operations on the Relational Database Model are
facilitated with the help of different conditional
expressions, various key attributes, pre-defined
constraints etc.
Keys…..



Candidate Key :Any field or a combination of fields that identifies a
record uniquely is called a Candidate Key. The
Candidate Key cannot contain NULL value and
should always contain a unique value.
Primary Key :Primary key is nothing but a candidate key that
identifies a record uniquely.
Foreign Key :A Foreign key is a primary key for other table, in
which it uniquely identifies a record. A Foreign Key
defines relation between two (or more) tables. A
Foreign key can contain NULL value.

Super Key :Given Relation Schema R with U is the list of
attributes, there are a set which is a subset of U. If
in a relation r of K with any two distinct tuples t1
and t2 we have the constraints that t1[K] ≠ t2[K]
then K is called a SUPER KEY of relation schema R.
A SUPER KEY is defined in the relational model as
a set of attributes of a relation variable (relvar) for
which it holds that in all relations assigned to that
variable there are no two distinct tuples (rows)
that have the same values for the attributes in this
set. Equivalently a super key can also be defined
as a set of attributes of a relvar upon which all
attributes of the relvar are functionally dependent.

Candidate Key :A Super Key can have a redundant attribute. A
super key that have no such attributes is called a
CANDIDTE KEY.
We can define a Candidate Key as follow :
Given relation schema R K’ is the candidate key of
R if K’ is satisfied two constraints :


K’ is a super Key of R.
There is no such a proper subset of K’ that is also
a super key of R or K’ is a minimal super key.
Since a relational schema can have more then one
Candidate Key thus there is a chosen candidate
key whose values are used to identify tuple in the
relation. Such a key is PRIMARY KEY. Primary key
is usually a most common candidate key.
Example :State Code
GJ3AB
HR4BC
MH4FF
GJ3BM
SrNo
9999
7
1000
6045
RegNo
G1235RF452
HR1546TT32
MH45HGJ215
GJ11HAS2125
Chassis No
1254GG54F
3256SDF45
458HYU789
653ASD458
Vehicle
HONDA CITY
HONDA CIVIC
HONDA CITY
PLATINA
Super Key :- {StateCode, SrNo, RegNo}, {RegNo}, {RegNo, ChassisNo}
Candidate Key :- {StateCode, SrNo}, {RegNo}
Primary Key :-{StateCode, SrNo}, {RegNo}
Fundamental Concepts in Relational Model

Domain :A domain D is the original sets of atomic values used to
model data.
•
•
•
By atomic, we mean that each value in the domain is
indivisible as far as the relational model is concerned.
For example:
The domain of day shift is the set of all possible days :
{Mon, Tue, Wed…}
The domain of salary is the set of all floating-point
numbers greater than 0 and less than 200,000 (say).
The domain of name is the set of character strings that
represents names of person

Relation :A relation is a subset of the Cartesian product of a list of
domains characterized by a name.
Relation can be viewed as a “table”. In that table, each row
represents a tuple of data values and each column
represents an attribute.

Attribute :A column of a relation designated by name. The name
associated should be meaningful. Each attributes associates
with a domain.

Relation Schema :Denoted by R is a list of attributes (A1, A2, …, An)
 The degree of the relation is the number of attributes of
its relation schema.
 The cardinality of the relation is the number of tuples in
the relation.
Characteristics of Relations

Ordering of Tuples in relation :A tuple is a set of values. A relation is a set of tuples.
Since a relation is a set, there is no ordering on rows.


Ordering of Values with a tuple :The order of attributes and their values within a relation is
not important as long as the correspondence between
attributes and values is maintained.
Values and NULL Values in the tuple :Each value in a tuple is atomic. That means each value
cannot be divided into smaller components. Hence, the
composite and multivalued attributes are not allowed in a
relation.
Constraints in Relational Data




Relational model support a well-defined theory of
constraint on attributes or tables.
Constraint is useful because it allows designer to
specify the semantics of data in database and it is
the rules to enforce DBMS to check that new data
satisfies the semantics.
Domain restrict the values of attributes in the
relation and it is a constraint of relational model.
We need more specific way to state what data
values are/are not allows, what format is suitable
for an attributes. For example, employee number
must be unique, employees’ age is in the range
[23, 65].


Such information is provided in logical statements
called integrity constraints.
There are several kinds of integrity constraints:



Key Constraints.
Referential Constraints.
Key Constraints :A relation is a set of tuples. By definition, all elements in a
set are distinct hence all tuple in a relation must be distinct.
In relational model, tuples have no identity like object –
identification. Tuple identity is totally value-based.
Therefore, we need key constraint that is the way of
uniquely identify a tuple.

There are many key constraints are there Like :






Super Key.
Primary Key.
Candidate Key.
Not Null.
Unique Key etc…
Referential Constraints :The constraint that is specified between two
relations and maintain the correspondence between
tuples in these relations. It means the reference
from a tuple in one relation to other relation must
be valid.
Referential constraint in relational model relates to
notation of foreign key.

Foreign Key Constraints :-
A Set of attributes FK in a relational schema R1 is foreign
key if :



The attributes in FK correspond to the attributes in the
primary key of another relation schema R2.
The value for FK in each tuple of R1 either occur as
values of primary key of a tuple in R2 or is entirely NULL
In a database of many relations, there are usually
many foreign keys. They provide the “glue” that
links individual relations into a cohesive database
structure.
Entity-Relationship Model



Entity-Relationship (E-R) data model was developed to
facilitate database design by allowing specification of an
enterprise schema that represent the overall logical
structure of a database.
The E-R model is very useful in mapping the meanings and
interaction of real-world enterprises into a conceptual
schema.
E-R data model employs three basic notations:



Entity Sets
Relationship Sets
Attributes
1. Entity Sets :
What is Entity ?


An Entity is a “Thing” or “Object” in real-world
that is distinguishable from all other objects.
e.g. Each person in an enterprise is an entity.
Entity has a set of properties and the values for
some set of properties may uniquely identify an
entity.
e.g. A person have a “personID” property and its
value “101-A45” would uniquely identify that
particular entity.

What is Entity Sets?


An Entity Set is the set of entities of the same
type that share some properties or attributes.
e.g. Set of all persons who are customer at a
given bank can be define as the entity set
customer.
Similarly entity set loan might represent the set
of all loans awarded by particular bank.
Entity Set do not need to be Disjoint.
e.g. It can be possible that entity set of all
employees of the bank and entity set of all
customer of the bank, so a person entity may be
employ or customer or both or neither of these.



An entity is represented by a set of
attributes.
The attributes are Descriptive Properties
processed by each member of an entity set.
Designation of an attribute for an entity set
expresses that the database stores similar
information concerning each entity.
e.g. Possible attributes for entity set customer :
custNo, custName, custAdd, custCity….etc…

Thus database includes a collection of entity
sets, each of which contains any number of
entities of the same types.
• A database usually contains groups of entities that are
similar. For example, a company employing
• hundreds of employees may want to store similar
information concerning each of the employees. These
• employee entities share the same attributes, but each
entity has its own value(s) for each attribute.
• An entity type defines a collection (or set) of
entities that have the same attributes.
• A few individual entities of each type are also
illustrated, along with the values of their attributes.
• The collection of all entities of a particular entity type
in the database at any point in time is called an entity
set; the entity set is usually referred to using
the same name as the entity type.
• For example :• EMPLOYEE refers to both a type of entity as well as
the current set of all employee entities in the
database.
• An entity type describes the schema or intension
for a set of entities that share the same
structure.
• The collection of entities of a particular entity type
are grouped into an entity set, which is also called
the
• extension of the entity type.
2. Relationship Sets :
What is Relationship?


A relationship is an association among several
entities.
e.g. We can define relationship that assciated
“Customer Hays Loan”.
What is Relationship Set?


A relationship Set is a set of relationship of the
same type.
It is mathematical relation on n > 2 entity sets.



If E1, E2……, En are entity set then the
relationship ser R is the subset of:
{(e1,e2…en)|e1 є E1, e2 є E2, …., en є En}
e.g. Entity sets Loan and entity set Branch which
define the relationship set Loan_Branch which
denote the association between Loan and Branch
in which the loan is maintain.
A function that entity plays in relationship is
called “Entity’s Role”.
Some entity sets participate in relationship set
more then once in different role called “Recursive
Relationship Set”.
e.g. Consider a entity set “employee” that records
the information about all the employees of bank
we may have a relationship “work for” that is
modeled by ordered pairs of “employee”.
So first employee pair work as Worker and
second employ pair work as Manager.

A relationship may also have attributes called
“Descriptive Attributes”.
e.g. Relationship Depositor with entity set Customer
and Account we can associate the attribute
Access_Date to relationship to specify the most
recent date a Customer access an Account.
Descriptive Attribute
Descriptive Attribute (Access_Date)
3. Attributes :


For each attribute, there is a set of permitted values
called the Domain or value set of that attribute.
The domain of attribute cust_name might be a set of
all text string of a certain length.
An attribute, as used in E-R Model, can be
characterize by the following attribute types:
1.
2.
3.
Simple and Composite Attributes.
Single-Value and Multivalued Attributes.
Derived Attributes.
3.1. Simple and Composite Attributes :
Attributes those used in our examples are of simple
attributes, they have not been divided into a
subpart.

Composite attribute on the other hand can be
divided into a subpart.

For example : An attribute name could be structured
as a composite attribute consisting of Surname,
Name, F_Name.
Name
Surname
Name
F_Name
Address
Street_Add
Street_No



City
Street_Nm
State
Zip
App_No
Attributes that are not divisible are called Simple or
Atomic Attributes.
If a composite referenced only as a whole there is no need
to subdivide it into component attributes.
For example if there is no need to refer to an individual
components of an address then the whole address can be
designated as a simple attribute.
3.2. Single-Value and Multivalued Attributes :





Most attributes nave a single value for any particular entity;
such attributes are called Single-Valued Attributes.
For example Age is a single-valued attribute of a person.
In some cases an attribute can have a set of values for the
same entity – for example, a color attribute for a car or a
college degree attribute for a person.
Cars with one color have a single value whereas two tones
cars have a two colors value.
Similarly one person may not have a college degree,
another person may have one college degree and third
person may have two or more college degree; therefore
different person may have different number of values for
the same attribute.
Such attributes are called Multivalued attributes.

Multivalued Attributes are shown in
E-R diagram using this symbol
3.3. Stored and Derived Attributes :

In some cases two or more attribute values are
related – for example Age and Birth_date
attributes of a person.
For a particular person entity the value of Age can
be determined from the current date and the value
of the person’s a Birth_Date. The Age attribute
hence called Derived Attribute and is said to be
Derivable Attribute from Birth_Date attribute which
is called Stored Attribute.
3.4. Null Value Attributes :



In some cases particular entity may not have an
applicable value for an attribute.
For example Apartment_No attribute of an address
applies only to address that are in apartment
building not to other type of residency. Similarly a
College_Degree attribute applies only to person
with college degree.
For such situation a special value called NULL is
created.
A single family home would have a NULL value for
Apartment_No and a person with no college
degree would have a NULL value for
College_degree.



In two cases the value of an attribute would have
the NULL.
 Known
 Unknown
Attribute value is exist but missing that is Known.
 E.g. :- Height of a Person
Attribute value when it not sure whether it is exist
or not that is Unknown.
 E.g. :- Home Phone.
3.5. Complex Attributes :
Composite and Multivalued Attributes can be nested
arbitrarily.

We can represent nesting by grouping components of a
composite attributes between Parentheses ( ) and
separating a component with comma (,) and by displaying
Multivalued attributes by Braces { }.

Such an attributes are called Complex Attributes.

For example a person can have more then one residencies
and each residency can have one address and multiple
phones then :
Address ( Sreet_add ( S_Num,S_Name,App_No), City,
State, Zip, Phone { Add_Phone (Code,Ph_No),
Mobile }
)
4. Alternative E_R Notations :Entity
Weak Entity
Relationship
Identifying
Relationship
Attribute
Multivalued
Attribute
Key Attribute
Derived
Attribute
Composite Attribute
Download