You are on page 1of 89

MODULE I

DBMS
DBMS-Introduction
• The collection of related data, is referred to as the
Database, contains information relevant to an
enterprise.

• A DataBase-Management System (DBMS) is a


collection of interrelated data and a set of programs
to access those data.

• The primary goal of a DBMS is to provide a way to


store and retrieve database information that is both
convenient and efficient.
Applications
• Enterprise Information
• Banking and Finance -customer information,
accounts, loans, and banking transactions
• Universities-For student information, course
registrations, and grades
• Airlines-For reservations and schedule information
of flights
• Human Resources-For information about
employees, salaries, payroll taxes,and benefits.
Purpose of Database Systems
• Before database management systems (DBMSs) were
introduced, organizations usually stored information
in file-based system in operating system.

• The system stores permanent records in various files,


and it needs different application programs to
extract records from, and add records to, the
appropriate files.
Disadvantages of file-based system

• Data redundancy and inconsistency


▫ Multiple file formats, duplication of information in different
files.

• Difficulty in accessing data.


▫ Need to write a new program to carry out each new task.

• Data isolation.
▫ Multiple files and formats.
Disadvantages
• Atomicity problems.
▫ Failures may leave database in an inconsistent state with
partial updates carried out.
▫ E.g. transfer of funds from one account to another should
either complete or not happen at all.

• Concurrent-access anomalies
▫ Uncontrolled concurrent accesses can lead to inconsistencies.
▫ E.g. two people reading a balance and updating it at the same
time.
• Integrity problems.
▫ The data values stored in the database must satisfy
certain types of consistency constraints.

• Security problems.
▫ Not every user of the database system should be able to access
all the data.
Disadvantages
▫ The above all disadvantages lead to the development
of database systems.
Advantages of DBMS
• Data Independence
Application programs should not, ideally, be
exposed to details of data representation and storage.
The DBMS provides an abstract view of the data that
hides 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.
Advantages of DBMS
• Data Integrity and Security
If data is always accessed through the DBMS,
the DBMS can enforce integrity constraints.
Also, it 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.
Advantages of DBMS
• 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. The DBMS protects users from the effects
of system failures.

• Reduced Application Development Time


The DBMS supports important functions that
are common to many applications accessing data
in the DBMS. This, in conjunction with the high-
level interface to the data, facilitates quick
application development.
THREE SCHEMA ARCHITECTURE /
VIEW OF DATA(Data Abstraction)
• A major purpose of a database system is to provide
users with an abstract view of the data.

• The system hides certain details of how the data are


stored and maintained.

• The developers hide the complexity from users


through several levels of abstraction, to simplify users’
interactions with the system.
Three levels of Abstraction
• Physical level.
▫ The lowest level of abstraction describes how the data
are actually stored.

▫ The physical level describes complex low-level data


structures in detail.

▫ How relations described in the conceptual schema is


actually stored on secondary storage devices .
• Logical level or conceptual level
▫ The next-higher level of abstraction describes what
data are stored in the database, and what
relationships exist among those data.

▫ Hides the details of physical storage and concentrates on


entities ,data types ,relationships and user operations.
• View level or External Schema
▫ The highest level of abstraction describes only part of the
entire database.

▫ Many users of the database system do not need all this


information; instead, they need to access only a part of
the database.

▫ The view level of abstraction exists to simplify their


interaction with the system. The system may provide
many views for the same database.
Data Independence
• The ability to modify a schema definition in one level
without affecting a schema definition in the next
higher level of data abstraction.
▫ Physical data Independence

▫ Logical data Independence


• Physical data Independence
▫ The ability to modify the physical schema without
changing the logical schema.
▫ Suppose there was a change in memory size of the
database servers.
▫ This will not affect the logical structure of any of
the objects in the database.
▫ They are completely independent of the physical
structure.
▫ This is called physical data independence.
• Logical data Independence
▫ The ability to modify the logical schema without
with out causing the application programs to be
rewritten.

▫ Any changes to the database objects like changes


to table structure, size or addition/removal of
columns from the table will not affect user views.

▫ They will see the data like before. This is called


logical data independence.
Schemas and instance

• The collection of information stored in the database at


a particular moment is called an instance of the
database.

• The overall design of the database is called the


database schema.
• The logical structure of database is schema.
DATABASE USERS

• Naive users/End users.


• Application Programmers.
• Sophisticated users.
• Specialized users
• DBA(Database Administrator)
Database Users

Naive users/ End Users –


• Any user who does not have any knowledge about
database can be in this category. There task is to just
use the developed application and get the desired
results.

▫ Examples, people accessing database over the web, bank


tellers, clerical staff
Database Users
Application programmers
• application programmers are the one who writes
application programs that uses the database.

• These application programs are written in


programming languages like COBOL ,Java and
fourth generation language.

• Retrieving information, creating new information and


changing existing information is done by these
application programs.
Database Users
Sophisticated users
• They are database developers, who write SQL
queries to select/insert/delete/update data.
• They do not use any application or programs to
request the database.
• They directly interact with the database by
means of query language like SQL.
• Eg)analyst,scientist
Database Users
• Specialized users:-
• These are also sophisticated users, but they write
special database application programs.
• They are the developers who develop the
complex programs to the requirement.
• Among these applications are computer aided-
design systems, knowledge-base and expert
systems etc.
DBA [DATABASE ADMINISTRATOR]

• A person who has such central control over the system is


called a database administrator (DBA).

• The DBA is responsible for many critical tasks:

Schema Definition
Schema and physical organization and modification
Granting of authorization of data access
Routine maintawnance
DBA [DATABASE ADMINISTRATOR]
Schema definition
• The DBA creates the original database schema by
executing a set of data definition statement in DDL.
DBA [DATABASE ADMINISTRATOR]
Schema and physical organization modification.

• The DBA carries out changes to the schema and


physical organization to reflect the changing needs of
the organization or to alter the physical organization
to improve.
DBA [DATABASE ADMINISTRATOR]
Granting of authorization for data access

• By granting different types of authorization ,the


database admin can regulate which parts of database
various users can access.
DBA [DATABASE ADMINISTRATOR]
Routine maintenance
• Periodic backing up the database.

• Ensuring that enough free disk space is available


for normal operation and upgrading disk space.

• Monitoring the jobs running on the database


and ensuring that performance is not degraded.
Database Languages

• SQL language.
▫ Data-definition language(DDL)-to specify the
database schema .

▫ Data-manipulation language(DML)- to express


database queries and updates.
Data-Manipulation Language
• A data-manipulation language (DML) is a
language that enables users to access or manipulate
data as organized by the appropriate data model.

• The types of access are:


•Retrieval of information
•Insertion of new information
•Deletion of information
• Modification of information
Data Definition Language
• The database schema is specified using set of
definitions expressed by a language called Data
Definition Language.
• The database system consists on integrity
constraints like:
E-R model
• The E-R data model is called Entity –Relationship
model.

• Widely used conceptual level data model .

• In ER modeling, the database structure is portrayed as


a diagram called an entity-relationship diagram.
• It is based on the concept that real world
consists of a collection of basic objects called
entities and relationship against these
entities.

• An entity is a thing or object in the real world


that is distingushable from other objects.
Entity set
• An entity set is a collection of similar types of
entities.

• An entity set may contain entities with attribute


sharing similar values.

• For example, a Students set may contain all the


students of a school; likewise a Teachers set may
contain all the teachers of a school from all
faculties
An Entity: Employees

name
ssn Address

Employees

An entity set is represented by a rectangle, and an attribute is represented by an oval.


Each attribute in the primary key is underlined.
Data modeling using E-R model
• Entities are described in a database by a set of
attributes.

• Eg1)an account entity may have account


number and balance may describe one
particular account in the bank ,and they are the
attibutes of account entity.
Relatioship
• Relationship: Association among two or more
entities. e.g., Jack works in Pharmacy
department.

• The attribute(s) used for describing the


relationship is called descriptive attributes,
also referred as relationship attributes.
• Relationship Set: Collection of similar
relationships.
NOTATIONS
• The overall logical structure of a database can be
expressed graphically by an E-R diagram.

• Rectangles –represents entity sets.

• Elipses -represent attributes.


▫ Double elipses-represent multivalued attributes
▫ Dashed elipses –denote derived attribute

• Diamond-represents set of relationship among member


from each of several entity sets.

• Lines-which link attributes to entity sets and entity sets


to relationships.
Example of E-R DIAGRAM
Different Types of Attributes

• Simple and composite attribute.


• Single valued and multi valued attribute.
• Derived attribute.
Different Types of Attributes
• Simple attribute:
 The attributes that cannot be divided into
subparts. Eg: Aadhar no:

• Composite attribute:
The attributes that can be divided into subparts.
Eg: Name –
first_name,middle_name,last_name.
Different Types of Attributes

• Single valued:
 hold a single value for a particular entity.
Eg : sid attribute for a student entity has only
one value. Not more than one value for sid is
alloted for a student.
Different Types of Attributes

• multi valued attribute.


 are those that have a set of values for a specific
entity.
Eg : phone no attribute of employee entity.
An employee can have zero, one or more than
one phone number. And different employees
may have different no: of phone numbers.
Different Types of Attributes
• Derived Attributes.

The value for this type of attribute can be derived


from other related attributes or entities.

Eg: loan_held attribute of Customer entity. Value


for this attribute is derived by counting the no: of
loan entities associated with that customer.

Another Eg: Age derived from date_of_birth


attribute.
Roles
• Roles are indicated in E-R diagrams by labelling
the lines that connect diamonds to rectangles.

• Role labels are optional, and are used to clarify


semantics of the relationship

• Entity sets of a relationship need not be distinct


worker
Work
employee
s for
Degree of relationship
• The degree of relationship is the number of
entities assosciated with a relationship.
• Relationship sets that involve two entity sets are
binary(or degree two).
• Generally, most relationship sets in a database
system are binary.
• Relationship sets may involve more than two
entity sets.
Degree of relationship
• The number of participating entities in a
relationship defines the degree of the
relationship.
• A unary relationship exist when an
assoscation is maintained by a single entity.
• Binary relationship exist when two entities
are assosciated.(degree 2)
• Ternary relationship exist when three
entities are assosciated.(degree 3)
Participation constraints
• There are two ways an entity can participate in a
relationship.
• Total participation-if every entity in entity
set E participates in at least one relationship in
relationship set R .
• e.g., each student must be guided by a professor
(there are no students who are not guided by any
professor).
Participation constraints
• Partial participation-if only some entites in
entity set E participates in relationship R then its
is partial participation.
• e.g., not every professor guides a student (there
are professors who don’t).
Mapping Cardinalities
• Mapping cardinalities are most useful in
describing binary relationship .
• For a binary relationship set the mapping
cardinality must be one of the following types:
▫ One to one
▫ One to many
▫ Many to one
▫ Many to many
• One-to-one
▫ 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 .
• One-to-many − One entity from entity set A
can be associated with more than one entities of
entity set B however an entity from entity set B,
can be associated with at most one entity.
• Many-to-one − More than one entities from
entity set A can be associated with at most one
entity of entity set B, however an entity from
entity set B can be associated with more than
one entity from entity set A.
• Many-to-many − One entity from A can be
associated with more than one entity from B and
vice versa.
STRONG ENTITY
• An entity set that has a primary key is termed as
a strong entity set.
WEAK ENTITY
• An entity set that does not have a primary key is
called a weak entity set.

• For a weak entity set to be meaningful, it must be


associated with another entity set called the
identifying / owner entity set.
• A weak entity can be identified uniquely only by
considering the primary key of owner entity.

▫ Owner entity set and weak entity set must participate in a


one-to-many relationship set (one owner, many weak
entities).

▫ Weak entity set must have total participation in this


identifying relationship set.
• The weak entity set must have total participation
in the identifying relationship set.

• The set of attributes of a weak entity set that


uniquely identify a weak entity for a given owner
entity is called a partial key of the weak
entity set.
• Double rectangles used ot represent weak entity
set
• Double diamond for weak entity relationship
• Dashed Line for discriminator or partial key.
Example
EXTENDED ER FEATURES
• We can add some extensions to ER model to
express some database features:
• Specialization
• Generalization
• Attribute inheritance
• aggregation
Specialization
• Specialization and Generalization define a
containment relationship between a higher level
entity set and one or more lower level entity set.

• Specialization is the result of taking a subset of a


higher level entity set to form a lower level entity set.

• Generalization is the result of taking union of two or


more disjoint lower level entity set to produce a
higher level entity set.
Specialization
• Specializaiton is denoted by a triangle labelled ISA.

• ISA stands for “is a”.

• Eg)a customer is person.

• The ISA relationship also referred to as superclass


-subclass relationship
EXAMPLE: SPECIALIZATION AND
GENERALIZATION
Generalization
• Generalization is like a bottom-up approach in
which two or more entities of lower level
combine to form a higher level entity if they have
some attributes in common.

• In generalization, entities are combined to form


a more generalized entity, i.e., subclasses are
combined to make a superclass.
Generalization
• Generalization is the simple inversion of
specialization.

• A lower-level entity set inherits all the attributes


and relationship participation of the higher-level
entity set to which it is linked.

• A lower-level entity set may have additional


attributes and participate in additional
relationships.
Constraints on generalization
• The may be certain 3 constraints on a particular
generalization.
I.One type of constraint on which entities can
be members of a given lower-level entity set:
• (i)Condition defined:-
▫ Membership is evaluated on the basis of whether or not
an entity satisfies an explicit condition or predicate.

▫ Eg)an account entity has an attribute account type,all


account having account type=saving will belong to
lower entity set saving account and account
type=checking will belong to lower entity set
checking account
(ii)User defined:-
• Here the database user assign entities to a given entity
set not by certain membership condition.

• Eg) After 3 months of employment bank employees


are assigned to one of 4 work teams .i.e emplyee entity
has 4 lower level entity.an employee is not assigned to
one of these 4 teams automatically but by the user in
charge of the decision makes team assignment on an
individual basis.
• II. Constraint on whether or not entities may
belong to more than one lower-level entity set
within a single generalization.
• Disjoint
▫ an entity can belong to only one lower-level entity set

▫ Eg)Account entity can only satisfy one condition for


account type attribute ,either saving or checking.
• Overlapping
▫ an entity can belong to more than one lower-level entity
set.
▫ Eg)Generalization applied to entity set customer and
employee .This is overlapping since employee can be an
customer.
• III. Completeness constraint
• Does an entity in the higher-level entity set have to
belong to at least one of the lower-level entity sets?
• Total Generalization
▫ an entity must belong to one of the lower-level entity
sets
• Partial Generalization
▫ an entity need not belong to one of the lower-level entity
sets
Aggregation
• One limitation of the E-R model is that it cannot
express relationship among relationship .
• One alternative for relationship is to create
quaternary relationship manages between
employee,branch,job and manager .

• This leads to redendency of information.

• This can be avoided by using aggregation .

• Aggregation is an abstraction through which


relationship are treated as higher level entities.
• Here the relatinship workson is treated as a
higher level entity set called works_on .

• Such entity set is treated as any other entity set .

• We the create a binary relationship among


works_on entity and manager entity .
Aggregation
NOTATIONS USED IN ER DIAGRAM
NOTATIONS USED IN ER DIAGRAM
ER Diagram: Banking Enterprise
Library management system
Data Models
• The different data models are :
▫ Relational Model.
▫ Entity-Relationship Model
▫ Object-Based Data Model
▫ SemiStructured Data Model.
Relational Model.
• The relational model uses a collection of tables to
represent both data and the relationships among
those data.
• Introduced by C.F Codd in 1970 and since then it has
been the most widely used database model

• Each table has multiple columns(attibutes), and each


column has a unique name.

• All the information related to a particular type is


stored in rows of that table.

• Tables are also known as relations.


Entity-Relationship Model
• The entity-relationship (E-R) data model uses a
collection of basic objects, called entities, and
relationships among these objects.

• An entity is a “thing” or “object” in the real world that


is distinguishable from other objects.
Object-Based Data Model.
• Object-oriented has become the dominant software-
development methodology.

• An object-oriented data model that can be seen


as extending the E-R model with notions of
encapsulation, methods (functions), and
object identity.

• The object-relational data model combines


features of the object-oriented data model and
relational data model.
Semistructured Data Model.
• The Extensible Markup Language (XML) is widely
used to represent semistructured data

• The semistructured data model permits the


specification of data where individual data items of
the same type may have different sets of attributes.

You might also like