dms_67a5e049ca806DBMS Module I
dms_67a5e049ca806DBMS Module I
Data (used as both singular and plural) is the known fact that can be recorded and have
implicit meaning.
Information is the refined data. When data is processed and presented in a form
suitable for human interpretation, it is called information. Data is the raw material and
information is the finished goods.
For Example: A list of students showing Regd. No, Name, Address, Course, Marks
obtained in each paper is called student’s data.
Data base: A collection of logically interrelated data stored together with controlled
redundancy to meet the needs of an organization is called database.
Components of Database:
Example:
Banking system is an example of DBMS which keeps information about the customers
and has a number of application programs:
Dr. A. K. Panda
To generate mini or, monthly statement etc
Advantages of DBMS:
Dr. A. K. Panda
Difference between File Management & Database Management
Characteristics of DBMS:
1. Self describing nature of DBMS: A database system contains not only the
database itself but also a complete definition or description of the database
structure and constraints. This definition is called metadata i.e. data about data
which is stored in a catalog called data dictionary. Hence data dictionary is a
data structure that stores metadata.
2. Data independence and data abstraction: In DBMS there is insulation between
data and programs called program-data independence. Hence data can be
changed without changing application programs. A DBMS provides users with a
conceptual representation of data that does not include many of the details of
how the data is stored or how the operations are implemented. This is called
program-operation independence. The characteristic that allows program-data
independence and program-operation independence is called data abstraction.
3. Support of multiple views of the data: A database typically has many users,
each of whom may require a different perspective or view of the database. A
view is a virtual data that is derived from the database files. Users may not need
to aware of whether the data they refer to is stored derived. A multiuser DBMS
provides different views for multiple users of the same database.
4. Data sharing and multiuser transaction processing: A multiuser DBMS allow
multiple users to access the database at the same time. A concurrency control
s/w is loaded to control multiple transactions.
There are different types of users who interact with the database with different level of
privileges and permissions.
Dr. A. K. Panda
1. Data Base Administrator (DBA):
An individual person or group of persons having central control over DBMS is called
DBA. They are the persons who are most familiar with the database and responsible for
creating, modifying and maintaining three levels of database. The DBA is also
responsible for authorizing access to the database, coordinating and monitoring its use
and acquiring software and hardware resources as needed.
Functions of DBA:
2. Database Designers:
3. Application Programmers:
4. End-Users:
The end-users are the clients for the database, which has been designed and
implemented. There are two types of end-users:
Dr. A. K. Panda
a) Naïve/ Parametric users: These users are the unsophisticated who don’t have
any DBMS knowledge but they frequently use the database applications in their
daily life to get the desired results. For example, Railway’s ticket booking users
are naive users. Clerks in any bank is a naive user because they don’t have any
DBMS knowledge but they still use the database and perform their given task.
b) Casual/ Temporary Users: These users interact with the database occasionally
and for specific purposes. They usually require the database for tasks that do not
occur on a daily basis but are crucial when needed. A marketing manager might
be a casual user who accesses the database quarterly to generate reports on
sales performance and customer demographics
c) Sophisticated users: These users are familiar with the structure of the database
and the facilities offered by the DBMS. Sophisticated users may use a high level
query language such as SQL to perform the required operation.
Dr. A. K. Panda
DATA BASE SYSTEM ARCHITECTURE
Schema: The overall description of the database is called as database schema. It is also a
plan or outline that describes the records at a particular level.
Employee
Department
Subschema: A subschema (or, scheme) is a subset of the schema and inherits the same
property that a schema has. It is an application programmer’s or, user’s view of the data
item types and record types. It gives the users a window through which he or, she can
view only part of the databases.
Dr. A. K. Panda
Fig: Subschema viewed by two application programs derived from above schema.
Instance: The collection of information stored in the database at any point of time is
called as an instance of the database.
Physical Data
Organization Database
Dr. A. K. Panda
1. External Level: This level describes the part of the database that is relevant to
each user.
2. Conceptual level: This level describes what data is stored in the database and
the relationships among the data.
3. Internal Level: This level describes how data is stored in the database.
Data Independence:
It means that upper levels are unaffected by changes in lower levels. It is achieved
through use of three levels of data abstraction.
Dr. A. K. Panda
Database languages:
Data Control Language (DCL): It is used to access the stored data. It is mainly
used for revoke and grant the user access to a database.
Dr. A. K. Panda
DATA MODEL
2. Physical data model: It provides concepts that describe the details of how data
is stored in the computer. Concepts provided by physical data models are
generally meant for computer specialists, not for the typical end-users. Physical
data models describes how data is stored as files in computer by representing
information such as record format, record orderings, and access paths. EX:
unifying model, frame memory model.
Data Model
Hierarchical Model:
Hierarchical data model was developed by IBM in 1968. A hierarchical data model is a
data model which the data is organized into a tree like structure with one-to-many
relationships between different types of data. The structure allows repeating
information using parent/child relationships: each parent can have many children but
each child only has one parent. To retrieve data from a hierarchical database, we need
to traverse whole tree.
Dr. A. K. Panda
Network Model:
Network model is the advance version of the hierarchical data model. It uses directed
graphs instead of the tree-structure to organize data. The data in the network model are
represented by collection of records and relationships among data are represented by
links, which can be viewed as pointers. The main difference between this model and the
hierarchical model is that any record can have several parents in the network model.
This data model is used to map many-to-many relationship.
Relational Model:
In 1970 E.F. Codd developed the relational data model .Unlike hierarchical data model
there are no physical links. Relational Model represents how data is stored in Relational
Databases. In this model, data is represented in the form of table only. It doesn’t deal
with the physical structure but only deals with data. It provides information regarding
metadata.
Dr. A. K. Panda
ENTITY-RLATIONSHIP MODEL
Entities
Attributes
Relationships
Entity: An entity is a person, place, object, event or concept that is uniquely identifiable.
An entity is called entity instance or entity occurrence.
Entity type (or set): It is a collection of entities that share common properties or
characteristics.
Example:
Dr. A. K. Panda
Classification of attributes:
An attribute that cannot be broken down into smaller components that are meaningful
for the organization is called simple attribute or atomic attribute.
An attribute that holds a single value for a single entity is called single-valued attribute
and an attribute that holds multiple values for a single entity is called Multivalued
attribute.
An attribute whose value is derived from value of another attribute is called derived
attribute and from which it is derived is called stored attribute.
Dr. A. K. Panda
Required vs. Optional Attribute:
An attribute that must be present for each entity instance is called a required attribute,
whereas an attribute that may not have a value is called an optional attribute.
Attribute Domain: Every attribute has a domain. A domain determines the type of data
values that are permitted for that attribute.
KEYS:
Super Key: An attribute or, a set of attributes that uniquely identifies an entity
in the entity type is called Super Key.
Candidate Key: A super key is said to be a candidate key if no proper subset of it
is a super key. That means minimal super key is called candidate key.
Primary Key: An entity type may have one or more possible candidate keys, one
of which is selected to be primary key. Database designer selects one of the
candidate key as primary key.
Composite key or concatenated key: A primary key that consists of two or
more attributes is called a composite key.
Alternate key: A candidate key that is not selected as primary key is called an
alternate key.
Secondary key: An attribute or, a set of attributes that is used to identify the
entities which have a certain property is called secondary key.
Relationship:
It is an association between instances of one or more entity types that is interest to the
organization.
Relationship type:
Degree of a Relationship:
It is the number of entity types that participate in that relationship. The three most
common relationship degrees in E-R models are unary (degree 1), binary (degree 2),
and ternary (degree 3).
Dr. A. K. Panda
Unary Relationship (or recursive relationship): It is a relationship between
the instances of a single entity type.
PERSON
EMPLOYEE
Is married
to
Manages
Registers
STUDENT COURSE
for
Quantity
PART
Hours
TEACHER
Dr. A. K. Panda
Structural Constraints:
1. Cardinality Constraint:
It specifies the number of instances of one entity that can be associated with each
instance of another entity. There are three basic types of cardinality constraints:
M N
A R B
2. Participation Constraint:
It specifies whether the existence of an entity depends on its being related to
another entity via the relationship type. There are two types of participation
constraints:
Dr. A. K. Panda
Example:
3. MIN/MAX Constraints:
The participation of an entity type in relationship type can be associated by a
pair of integers (MIN, MAX) as follows:
(MIN, MAX)
A R
It means that each entity instance of the entity type A participates in at least MIN
and at most MAX relationship instances at any point of time.
Note: If MIN = 0, then the participation is partial and if MIN > 0, then the
participation is total.
Example:
(1, 1) (4, N)
EMPLOYEE Works for DEPARTMENT
Each employee works for at least one department and at most one department and
each department have at least 4 employees and at most unlimited employees.
The entity type that does not have sufficient attributes to form a primary key is called a
weak entity type. On the other hand, an entity type that has a primary key is called
strong entity type.
Note: The participation of weak entity type is always total but the converse is not true.
Example:
EMPLOYEE Claims DEPENDENT
Dr. A. K. Panda
Identifying Relationship:
A relationship in which the primary key of the parent entity is used as a part of the
primary key of the dependent entity is called identifying relationship.
Representation in ERD:
Partial Key:
It is a set of attributes that uniquely identify weak entities that are related to the same
owner entity.
Representation in ERD:
Example:
City
Street
Ename
Sex
Empid State Dname Birth date
Addres
s (1, 1)
(0, N)
EMPLOYEE Claims DEPENDENT
3. Attribute
4. Multi-valued Attribute
5. Derived Attribute
Dr. A. K. Panda
7. Partial key Attribute
…
8. Composite Attribute
9. Relationship
1 1
14. E1 R E2 One-to-One relationship
1 N
15. E1 R E2 One-to-Many relationship
M N
16. E1 R E2 Many-to-Many relationship
(MIN, MAX)
17. E R MIN/ MAX Constraint
Dr. A. K. Panda
Example:
Draw an ER diagram of book club. The book club has members. The book club sells
books to its members. The members place orders for books, which the book club fulfils.
Each order contains one or more than one book. An author can write more than one
book and a book can have more than one author. A book is published by a publisher but
a publisher publishes many books. The book club sells many books.
(1, 1) (1, N)
MEMBER Enrolls in BOOK_CLUB
AUTHOR
Fulfils
Places
Sells (1, N)
(1, 1)
(1, 1) (1, N)
(1, 1)
ORDER
BOOK Writes
(1, 1)
(1, N)
(1, 1)
Publishes
(1, N)
Contains PUBLISHER
Dr. A. K. Panda
Example: ER diagram of Project handling company.
Controls
(1, 1)
Supervises (1, N)
Works on PROJECT
Proj-id Location
Hours Pname
Dr. A. K. Panda
Example: ER diagram of banking organization.
Locality City
Plot-No State
Locality City
M N
CUSTOMER Cust-Banker EMPLOYEE Manages
1
1
N
Balance
Deposits ACCOUNT
A/C-No
N
Borrows
Transaction-Date
Opens
N 1
Loan-No N 1
LOAN Loan-branch BRANCH
Amount 1
Branch-Name Assets
City
Loan
Payment
PAYMENT
Payment-No Payment-Date
Payment-Amount
Dr. A. K. Panda
ENHANCED ENITY RELATIONSHIP (EER) MODEL
The EER model consists of all the concepts of E-R model together with the following
additional concepts:
Specialization
Generalization
Categorization
Aggregation
Supertype or, Superclass: It is a generic entity type that has a relationship with one or
more subtypes.
Example:
Shared Attributes
SUPERTYPE
Dr. A. K. Panda
Attribute Inheritance:
It is a property by which subtype entities inherit values of all attributes and instance of
all relationships of the Supertype.
Specialization:
Pname S
Patient-id Admin-Date P
G E
E C
N PATIENT
I
E A
R L
A I
L Z
I A
Z T
INPATIENT OUT-PATIENT
A I
T O
I N
O
N Check-back-Date Date-discharged
Generalization:
Participation constraint
Disjointness constraint
Dr. A. K. Panda
Participation Constraint:
Total Participation
Partial participation
Total participation constraint: It specifies that each entity of the supertype must be a
member of some subtype in the Specialization/ Generalization.
Representation in ERD:
SUPERTYPE
Example:
Ename
Empid Address
EMPLOYEE
Annual-Salary Billing-rate
Hourly-rate Contract-no
It specifies that a member of the Supertype need not belong to any of its subtypes of a
specialization/generalization.
Dr. A. K. Panda
Example:
Make Model
V-Name Engine-No
Vehicle-No Chassis-No
VEHICLE
Disjointness Constraint:
Disjoint Constraint
Overlapping constraint
Disjoint Constraint:
Representation in ERD:
SUPERTYPE
Dr. A. K. Panda
Example:
Name
A/C-No Address
ACCOUNT
Overlapping Constraint:
Representation in ERD:
SUPERTYPE
Example:
Ename Description
Empid Salary Part-No Type
EMPLOYEE PART
O
O
Routine-No Unit-Price
Dr. A. K. Panda
Hence, we have following four possible constraints on specialization/generalization:
Disjoint, total
Disjoint, partial
Overlapping, total
Overlapping, partial
Example:
Name
Person-id Address
PERSON
O
Major
Date-hired
Year
Section
Regd-no
FACULTY STAFF GRADUATE UNDER GRADUATE
Rank Position
CGPA Percentage
It is the process of modeling of a single subtype (or subclass) with a relationship that
involves more than one distinct supertype (or superclass).
…
Representation in ERD: Supertype-1 Supertype-2 Supertype-n
SUBTYPE
Dr. A. K. Panda
Example:
EMPLOYEE DEPARTMENT COMPANY
OWNER
Aggregation:
Requires
GUIDE
Dr. A. K. Panda
Example: EER diagram of Hospital database
Total-Cost
I-code Unit-Price
Name
T-Code Price
N
Is billed ITEM
for TEST
Name Specialty
Name
Phy-id
Patient-id Admit-date Tel-No
M
PATIENT Advices PHYSICIAN
Age Ph.No
Name
d
Prescribes
DRUG
OUT-PATIENT IN-PATIENT 1
Date Quantity N
Company
Checkbackdate Discharge-date
Ph.No Name
Type Price
1
ROOM PHARMACY
Treat-Code Room-No Bed-No
Roomid
TREATMENT Treats
Result
Date
Description Time
Dr. A. K. Panda
RELATIONAL DATA MODEL
The relational model was first introduced in 1970 by Dr. E. F. Codd of IBM. The
relational model represents data in the form of tables.
Relation: It is a named two dimensional table of data with rows and columns.
Attribute: It is a named column of a relation.
Domain: It is a set allowable value of an attribute.
Tuple: It is a row of a relation.
Degree: The degree of a relation is the no. of attributes it contains.
Cardinality: The cardinality of a relation is the number of tuples it contains.
Relational Database: It is a collection of normalized or structured relations with
distinct relation names.
Types of Keys:
Super key: An attribute or, a set of attributes that uniquely identifies a tuple
with in a relation is called Super Key.
Candidate Key: A super key is said to be a candidate key if no proper subset of it
is a super key. That means minimal super key is called candidate key.
Primary Key: A relation may have one or more possible candidate keys, one of
which is selected to be the primary key. Database designer selects one of the
candidate key as primary key.
Composite key or concatenated key: A primary key that consists of two or
more attributes is called a composite key.
Alternate key: A candidate key that is not selected as primary key is called an
alternate key.
o 𝐴𝐾 = 𝐶𝐾 − 𝑃𝐾
Secondary key: An attribute or, a set of attributes that is used to identify the
entities which have a certain property is called secondary key.
Foreign key: An attribute in a relation that serves as the primary key of another
relation is called in the same database is called foreign key.
Dr. A. K. Panda
Properties of relations:
Integrity Constraints:
Relational data model includes several constraints whose purpose is to maintain the
accuracy and integrity of the data in the database. The major types of integrity
constraints are:
1. Domain constraint (Check): It specifies that the value of each attribute A must
be atomic value from the domain of A.
2. Key constraint (unique): It specifies that all tuples in a relation must be distinct.
3. Entity Integrity constraint (not null): It specifies that primary key cannot
accept null values.
4. Referential Integrity Constraint (Foreign key): It specifies the value of the
referencing attribute (Foreign key) is either null or it is equal to value of the
referenced attribute.
Example:
Dr. A. K. Panda
CODD’S 12 Rules:
Dr. A. K. Panda
TRANSFORMATION OF ER MODEL INTO RELATIONS
During logical design, the ER diagrams (developed during conceptual design) are
translated into relational database schemas. The inputs to this process are the ER
diagrams and the outputs are collection of tables (or, relations) with associated
constraints. Transforming (or mapping) ER diagrams to relations is a straightforward
process with a well-defined set of rules.
Transform each (strong) entity type in an E-R diagram into a relation. The primary key
of the entity type becomes the primary key of the corresponding relation. Each simple
attribute of the entity type becomes an attribute of the relation. If one attribute is
composite, include the simple components of the composite attribute.
Mname
Fname Lname
Cname Sex
Custid
Address
CUSTOMER
For each weak entity type, create a new relation and include all of the simple attributes
as attributes of this relation. Then include the primary key of the parent entity type as
foreign key attribute in this new relation. The primary key of the new relation is the
combination of the primary key of the parent entity type and the partial key of the weak
entity type.
City
Street
Ename
Sex
Empid State Dname Birth date
Addres
s (1, 1)
(0, N)
EMPLOYEE Claims DEPENDENT
Dr. A. K. Panda
EMPLOYEE (Empid, Ename, Street, City, State)
When the entity type contains a multivalued attribute, two new relations are created.
The first relation contains all the attributes of the entity type except the multivalued
attribute. The second relation contains two attributes that form the primary key of the
second relation. The first of these attributes is the primary key of the first relation,
which becomes a foreign key in the second relation and the second is the Multivalued
attribute.
Pname
Phy-id Salary
For each binary one-to-one relationship R between two entity types A and B, first create
a relation for each of the two entity types, say R 1 and R2 respectively. Then choose one
of the relations (say R1) and include as foreign key in R 1 the primary key of B. (It is
better to choose an entity type whose participation is total.) Include all the simple
attributes of the relation type R as attributes of R1.
Ename Dname
Start-Date
Deptid
Salary Location
Empid
1 1
EMPLOYEE Manages DEPARTMENT
Dr. A. K. Panda
Step 5: Mapping of Binary One-to-Many Relationships
For each binary one-to-many relationship, first create a relation for each of the two
entity types participating in the relationship. Next, include the primary key attribute of
the entity on the one-side of the relationship as a foreign key in the relation that is on
the many-side of the relationship (PK migrates to the many side). Then include the
simple attributes of the relationship as attributes of the relation that is on the many-
side.
Cname
Orderid O-Date
Custid Address
1 N
CUSTOMER Places ORDER
For each binary many-to-many relationship R, between two entity types A and B, create
a relation for each participating entity types (say, R1 and R2) and create a separate
relation for the relationship (say R3). The primary key of this relation is a composite
key consisting of the primary keys of the participating entity types. Include the simple
attributes of relationship type R as attributes of R3.
Description
Quantity
M N
ORDER REQUESTS PRODUCT
Dr. A. K. Panda
Step-7: Mapping of Unary Relationships (or, recursive relationships)
For each unary one-to-one or, one-to-many relationship, create a single relation to
represent both entity type and relationship type. The primary key of this relation is the
primary key of the entity type. Then include the primary key of the same entity type as
foreign key of the relation.
Sex
Pname Addre
ss
Is
married
to
Ename
Empid Address
Manages
For each unary many-to-many relationship, create two relations: one to represent the
entity type in the relationship and the other an associative relation to represent the M:
N relationship itself. The primary key of the associative relation consists of two
attributes (which need not have the same name) both take their values form the
primary key of the other relation. Then include simple attributes of the relationship as
attributes of the associative relation.
Dr. A. K. Panda
Description
Item-No Unit-Price
Contains
Quantity
For each n-ary (n 2) relationship type R, create a new relation S to represent R. The
primary key of this relation consists of the primary key attributes for the participating
entity types. Then include the simple attributes of R as attributes of the relation S.
Pname Color
Pno Weight
Sname Status
PART Jname
Jno
Sno City
City
Quantity
Dr. A. K. Panda
Step-9: For each specialization / generalization, create a relation for the Superclass,
which contains the primary and all non key attributes in common with all subclasses,
plus create a separate relation for each subclass with the same primary key but with
only non key attributes related to that subclass.
Ename
Empid Address
Basic
Hourly-wages Hours-worked
Dr. A. K. Panda