Introduction to Relational Database Systems
Introduction to Relational Database Systems
UNIT - I
Purpose of Database Systems - Overall system structure - Entity
relationship model - Mapping constraints - Primary Keys - Foreign
Keys - E.R. Diagrams.
DATABASE:
Database is a collection of interrelated (organized) data.
DBMS:
ADVANTAGES OF A DBMS
Using a DBMS to manage data has many advantages:
Data independence: Application programs should be as independent as
possible from details of data representation and storage. The DBMS can
provide an Abstract view of the data to insulate application code from such
details.
Efficient data access: A DBMS utilizes a variety of sophisticated
techniques to Store and retrieve data efficiently. This feature is especially
important if the data is stored on external storage devices.
Data integrity and security: If data is always accessed through the
DBMS, the DBMS can enforce integrity constraints on the data. For
example, before inserting salary information for an employee, the DBMS
can check that the department budget is not exceeded. Also, the DBMS can
enforce access controls that govern what data is visible to different classes
of users.
Data administration: When several users share the data, centralizing the
administration of data can offer significant improvements. Experienced
professionals who understand the nature of the data being managed, and
how different groups of users use it, can be responsible for organizing the
data representation to minimize redundancy and for fine-tuning the storage
of the data to make retrieval Efficient.
Concurrent access and crash recovery: A DBMS schedules concurrent
accesses to the data in such a manner that users can think of the data as
being accessed by only one user at a time. Further, the DBMS protects
users from the effects of system failures.
Reduced application development time: Clearly, the DBMS supports
many important functions that are common to many applications accessing
data stored in the DBMS. This, in conjunction with the high-level interface
to the data, facilitates quick development of applications. Such applications
are also likely to be more robust than applications developed from scratch
because many important tasks are handled by the DBMS instead of being
implemented by the application.
Given all these advantages, is there ever a reason not to use a DBMS? A
DBMS is a complex piece of software, optimized for certain kinds of
workloads (e.g., answering complex queries or handling many concurrent
requests), and its performance may not be adequate for certain specialized
applications. Examples include applications with tight real-time constraints
or applications with just a few well-defined critical operations for which e
client custom code must be written. Another reason for not using a DBMS
is that an application may need to manipulate the data in ways not
supported by the query language. In such a situation, the abstract view of
the data presented by the DBMS does not match the application’s needs,
and actually gets in the way. As an example, relational databases do not
support exible analysis of text data (although vendors are now extending
their products in this direction). If specialized performance or data
manipulation requirements are central to an application, the application
may choose not to use a DBMS, especially if the added benefits of a DBMS
(e.g., exible querying, security, concurrent access, and crash recovery) are
not required. In most situations calling for large-scale data management,
however, DBMSs have become an indispensable tool.
STRUCTURE OF DBMS
The various components of DBMS are shown below: -
1. DDL Compiler - Data Description Language compiler processes
schema definitions specified in the DDL. It includes Metadata ( is “data
about data.” or “Information about data”) metadata information such as
the name of the files, data items, storage details of each file, mapping
information and constraints etc.
2. DML Compiler and Query optimizer - The DML commands such as
insert, update, delete, retrieve from the application program are sent to
the DML compiler for compilation into object code for database access.
The object code is then optimized in the best way to execute a query by
the query optimizer and then send to the data manager.
3. Data Manager - The Data Manager is the central software component
of the DBMS also knows as Database Control System.
. Data Dictionary - Data Dictionary is a repository of description of data
in the database. It contains information about Database.
• Data - names of the tables, names of attributes of each table, length of
attributes, and number of rows in each table.
• Relationships between database transactions and data items
referenced by them which is useful in determining which transactions
are affected when certain data definitions are changed.
• Constraints on data i.e. range of values permitted.
• Detailed information on physical database design such as storage
structure, access paths, files and record sizes.
• Access Authorization - is the Description of database users their
responsibilities and their access rights.
• Usage statistics such as frequency of query and transactions
Relationship Types
• We may distinguish four different types of relationships based on
the cardinalities of the upper bounds on either side of the
relationship
1:1
1:M
M:1
M: M
1:1- Relationship
An entity in A is associated with atmost one entity
in B, and an entity in B is associated with atmost one entity in A.
A B
A A
B
C
A A
B
C
A A
B B
C C
Primary Keys:
A primary key is the column or a group of columns
that can uniquely identify any row in the table. This key should also
identify the table through the database. Listed below are some of the
important elements of a primary key:
It must uniquely identify each record in a table.
It must contain unique values.
It cannot be a null field.
It cannot be a multi-part field.
It should contain a minimum number of fields necessary to be
called unique.
Its value cannot be modified except in very rare cases.
We have seen that in this table the member code is the primary
key. Whenever a new member joins the library, a unique number will be
assigned to the member. This number will not be assigned to anyone else
so that it can remain unique. Numbers are preferred as key as they can
remain unique. Member’s names could be duplicates, so they cannot
qualify as primary keys.
Listed below are some rules for establishing primary keys:
Each table must have only one primary key.
Each table within a database should have a unique primary key.
Foreign Keys:
A foreign key is a copy of a primary key in another
table. The key connects to another table when a relationship is being
established. Consider the issues table again.
Mem-Cd Book Code Issue Date Return Date
M001 B0020 18-3-98 18-4-98
M008 B0189 18-3-98 18-4-98
M067 B0656 19-3-98 19-4-98
M0123 B0198 20-3-98 20-4-98
Mapping Constraints:
It contains two most important types of
constraints,
Mapping Cardinalities
Existence dependencies
Mapping Cardinalities
Mapping Cardinalities, or cardinality ratios,
express the number of entities to which another entity can be
associated via a relationship set.
Mapping cardinalities are useful in
describing binary relationship sets. For a binary relationship set R
between entity sets A and B, the mapping cardinality must be one of
the following:
One to One:
An entity in A is associated with at most one
entity in B,and an entity in B is associated with at most one entity
in A.
One to Many Relationship :
An entity in A is associated with any
number of entities in B,An entity in B,however,can be associated
with at most one entity in A.
Many to One Relationship :
An entity in A is associated with at most
one entity in [Link] entity in B, however, can be associated with any
number of entities in A.
Many to Many Relationship:
An entity in A is associated with any
number of entities in B, and an entity in B is associated with any
number of entities in A.
Existence Dependencies
Another important class of constraints is
existence [Link],if the existence of entity X
depends on the existence of entity Y,then X is said to be existence
dependent on [Link],if Y is deleted, so is [Link] Y is said
to be a dominant entity, and X is said to be a subordinate entity.
Consider the entity set Loan and the entity
set Payment that keeps information about all the payments that
were made in connection to a particular loan.
The Payment entity set is described by the
attributes payment number, payment-date, and payment-amount.
We form a relationship set loan-payment between these two entity
sets. which is one to many from loan to payment.
Every payment entity must be associated
with a loan entity. if a loan entity is deleted, then all its associated
payment entities must be deleted also.
In contrast, payment entities can be deleted from
the database without affecting any loan. The entity set Loan is dominant,
and payment is subordinate, in the loan-payment relationship set.
E-R Diagram:
The overall logical structure (schema) of a database can be expressed
graphically by an E-R diagram, which is built up from the following
components:
Derived Attributes
There may be a case when two or more attributes values are related.
Take the example of age. Age of a person can be calculated from
person’s date of birth and present date. Difference between the two gives
the value of age. In this case, age is the derived attribute.
The attribute from which another attribute value is derived is called
stored attribute. In the above example, date of birth is the stored
attribute. Take another example, if we have to calculate the interest on
some principal amount for a given time, and for a particular rate of
interest, we can simply use the interest formula
Interest=NPR/100;
In this case, interest is the derived attribute whereas principal
amount(P), time(N) and rate of interest(R) are all stored attributes.
Derived attributes are usually created by a formula or by a summary
operation on other attributes.
Composite
Street
Address
City
State Simple
DOB
Null
Passport
port
Phone
No’s
Multi-valued
Age Derived
drive
Person s Car
SUBJECT
Requires
Child Instrument
Plays
Example of Ternary Relationship set
An entity set may not have sufficient attributes to form a primary key.
Such an entity set is termed a weak entity set. An entity set that has a
primary key is termed a strong entity set.
As an illustration, consider the entity set payment, which has the
three attributes: Payment-number, payment-date, and payment-amount.
Payment numbers are typically sequential numbers, starting from 1,
generated separately for each loan. Thus, although each payment entity
is distinct, payments for different loans may share the same payment
number. Thus, the entity set does not have a primary key; it is a weak
entity set.
For a weak entity set to be meaningful, it must be associated with
another entity set, called the identifying or owner entity set. Every weak
entity must be associated with an identifying entity; that is, the weak
entity set is said to be existence dependent on the identifying entity set.
The identifying entity set is said to own the weak entity set that it
identifies. The relationship associating the weak entity set with the
identifying entity set is called the identifying relationship. The
identifying relationship is many to one from the weak entity set to the
identifying entity set, and the participation of the weak entity set in the
relationship is total.
In our example, the identifying entity set for payment is loan, and
a relationship loan-payment that associates payment entities with their
corresponding loan entities is the identifying relationship.
Although a weak entity set does not have a primary key, we
nevertheless need a means of distinguishing among all those entities in
the weak entity set that depend on one particular strong entity. The
discriminator of a week entity set is a set of attributes that allows this
distinction to be made. For example, the discriminator of the weak entity
set payment is the attribute payment-number, since, for each loan, a
payment number uniquely identifies one single payment for that loan.
The discriminator of a weak entity set is also called the partial key of the
entity set.
The primary key of the identifying entity set, plus the weak entity
set’s discriminator forms the primary key of a weak entity set. In the
case of the entity set payment, its primary key is {loan-number,
payment-number}, where loan-number is the primary key of the
identifying entity set, namely loan, and payment-number distinguishes
payment entities within the same loan.
The identifying relationship set should have no descriptive
attributes, since any required attributes can be associated with the weak
entity set.
A weak entity set can participate in relationships other than the
identifying relationship. For instance, the payment entity could
participate in a relationship with the account entity set, identifying the
account from which the payment was made. A weak entity set may
participate as owner in an identifying relationship with another weak
entity set. It is also possible to have a weak entity set with more than
one identifying entity set. A particular weak entity would then be
identified by a combination of entities, one from each identifying entity
set. The primary key of the weak entity set would consists of the union
of the primary keys of the identifying entity sets, plus the discriminator
of the weak entity set.
In E-R diagrams, a doubly outlined box indicates a weak entity set,
and a doubly outlined diamond indicates the corresponding identifying
relationship. In Figure 2.16, the weak entity set payment depends on the
strong entity set loan via the relationship set loan-payment.
The figure also illustrates the use of double lines to indicate total
participation—the participation of the (weak) entity set payment in the
relationship loan-payment is total, meaning that every payment must be
related via loan-payment to some loan. Finally, the arrow from loan-
payment to loan indicates that each payment is for a single loan. The
discriminator of a weak entity set also is underlined, but with a dashed,
rather than a solid, line.
In some cases, the database designer may choose to express a
weak entity set as a multivalued composite attribute of the owner entity
set. In our example, this alternative would require that the entity set
loan have a multivalued, composite attribute payment, consisting of
payment-number, payment-date, and payment-amount. A weak entity
set may be more appropriately modeled as an attribute if it participates
in only the identifying relationship, and if it has few attributes.
Conversely, a weak- entity-set representation will more aptly model a
situation where the set participates in relationships other than the
identifying relationship, and where the weak entity set has several
attributes.
payment-date
loan-
number amoun
t
payment- payment-
number amount
loan-
loan paymen
t
payment