Chapter 2
Chapter 2
The name given to an entity should always be a singular noun descriptive of each item to
be stored in it. E.g.: student NOT students.
Every relation has a schema, which describes the columns, or fields the relation itself
corresponds to our familiar notion of a table:
A relation is a collection of tuples, each of which contains values for a fixed number of
attributes
Existence Dependency: the dependence of an entity on the existence of one or more
entities.
Weak entity : an entity that cannot exist without the entity with which it has a relationship
– it is indicated by a double rectangle
This type of entity has not primary key. In order to isolate each tuples it uses partial
key. However sometimes partial key is duplicate. At that time it is difficult to isolate
each tuple uniquely.
2. The ATTRIBUTES - the items of information which characterize and describe these entities.
Attributes are pieces of information about entities. The analysis must of course identify those
which are actually relevant to the proposed application. Attributes will give rise to recorded
items of data in the database
At this level we need to know such things as:
Attribute name (be explanatory words or phrases)
The domain from which attribute values are taken (A DOMAIN is a set of
values from which attribute values may be taken.) Each attribute has values
taken from a domain. For example, the domain of Name is string and that for
salary is real
Whether the attribute is part of the entity identifier (attributes which just
describe an entity and those which help to identify it uniquely)
Whether it is permanent or time-varying (which attributes may change their
values over time)
Whether it is required or optional for the entity (whose values will sometimes
be unknown or irrelevant)
Types of Attributes
(1) Simple (atomic) Vs Composite attributes
Simple : not divided into sub parts
E.g. Age, gender
Composite: Divided into sub parts (composed of other attributes)
E.g. Name, address
(2) Single-valued Vs multi-valued attributes
Single-valued : have only single value(the value may change but has only
one value at one time)
E.g. Name, Sex, Id. No. color_of_eyes
Multi-Valued: have more than one value
E.g. Address, dependent-name
Person may have several college degrees
3. RELATIONSHIPS between entities which exist and must be taken into account when
processing information. In any business processing one object may be associated with another
object due to some event. Such kind of association is what we call a RELATIONSHIP between
entity objects.
One external event or process may affect several related entities.
Related entities require setting of LINKS from one part of the database to another.
A relationship should be named by a word or phrase which explains its function
Role names are different from the names of entities forming the relationship: one
entity may take on many roles, the same role may be played by different entities
For each RELATIONSHIP, one can talk about the Number of Entities and the
Number of Tuples participating in the association. These two concepts are called
DEGREE and CARDINALITY of a relationship respectively.
Degree of a Relationship
An important point about a relationship is how many entities participate in it. The
number of entities participating in a relationship is called the DEGREE of the
relationship.
Relational Integrity
Domain Integrity: No value of the attribute should be beyond the allowable
limits
Entity Integrity: In a base relation, no attribute of a Primary Key can
assume a value of NULL
Referential Integrity: If a Foreign Key exists in a relation, either the
Foreign Key value must match a Candidate Key value in its home
relation or the Foreign Key value must be NULL
Enterprise Integrity: Additional rules specified by the users or database
administrators of a database are incorporated
Key constraints
If tuples are need to be unique in the database, and then we need to make each tuple distinct.
To do this we need to have relational keys that uniquely identify each relation.
Super Key: A Super Key is a set of one or more attributes that are taken collectively and
can identify all other attributes uniquely.
Candidate Key: are a super key which are not having any redundant attributes. In other
words candidate keys are minimal super keys
Candidate key has two properties:
1. Uniqueness
2. Irreducibility
Primary Key: the candidate key that is selected to identify tuples uniquely within the
relation.
The entire set of attributes in a relation can be considered as a primary case
in a worst case.
For example:- Book (bookid, bookname, author)
(BookId)
(BookId,BookName)
(BookId, BookName, Author)
(BookId, Author)
(BookName, Author)
As our Super key. Each super key is able to uniquely identify each tuple.
From the above super key, we can take candidate key which are not having any
redundant. That means (bookid) and (bookname, author) can be the candidate
key. The other keys have redundant attribute.
From those candidate key, database designer choose the primary key which
uniquely identify each tuple. So (bookid) is considered as the primary key in this
condition. But you can choose also (bookname, author) as a primary key. But it
is complex when we use two or more than two attribute as a primary key.
Foreign Key: an attribute, or set of attributes, within one relation that matches the
candidate key of some relation.
A foreign key is a link between different relations to create the view or the
unnamed relation
Relational Views
Relations are perceived as a Table from the users’ perspective. Actually, there are two kinds of
relation in relational database. The two categories or types of Relations are Named and Unnamed
Relations. The basic difference is on how the relation is created, used and updated:
1. Base Relation
A Named Relation corresponding to an entity in the conceptual schema, whose tuples are
physically stored in the database.
2. View (Unnamed Relation)
A View is the dynamic result of one or more relational operations operating on the base
relations to produce another virtual relation that does not actually exist as presented. So a
view is virtually derived relation that does not necessarily exist in the database but can
be produced upon request by a particular user at the time of request. The virtual table or
relation can be created from single or different relations by extracting some attributes and
records with or without conditions.
Purpose of a view
Hides unnecessary information from users: since only part of the base relation
(Some collection of attributes, not necessarily all) are to be included in the virtual
table.
Provide powerful flexibility and security: since unnecessary information will be
hidden from the user there will be some sort of data security.
Provide customized view of the database for users: each users are going to be
interfaced with their own preferred data set and format by making use of the Views.
A view of one base relation can be updated.
Update on views derived from various relations is not allowed since it may violate
the integrity of the database.
Update on view with aggregation and summary is not allowed. Since aggregation
and summary results are computed from a base relation and does not exist actually.