Unit 1 DBMS
Unit 1 DBMS
Sum of both
account before
transfer is 3000
Person Person
A Transfer 500 B
Account Account
A Step 1 : Debit 500 from B
Bal : Account A Bal : Sum of both
Transactio
2000 Step 2 :Sum of both
Credit 500 into 1000 account is
n is failed accountB 2500
Account
after transfer is so
3000 inconsistent
Allow to implement integrity
constraints
Addre Mobile_N Subje
Emp_Name
ss o ct
Prof. Ajay 98765432
PPS
Pune Should contain exact
Sen 10
10 digits
Student_Na Branc
Backlog SPI
me h
Nirav Patel Rajkot 0 8.5
Should be between
0 to 10
Facul
ty Addre Mobile_N Subje
Emp_Name
ss o ct
Prof. Ajay 98765432
Rajkot PHY
Shah 10
Prof. Ajay 01234567 DBM
Surat
Patel 89 S
• Field
• A field is a character or group of characters that have a specific meaning.
• E.g, the value of Emp_Name, Address, Mobile_No etc are all fields of Faculty table.
Facul
ty Addre Mobile_N Subje
Emp_Name Fields
ss o ct
Prof. Ajay 98765432 Prof. Ajay Rajkot 9876543
Rajkot PHY
Shah 10 Shah 210
Prof. Ajay 01234567 DBM
• Record
Patel / Tuple
Surat
89 S
• A record is a collection of logically related fields.
• E.g, the collection of fields (Emp_Name, Address, Mobile_No, Subject) forms a
record for the Faculty.
Prof. Ajay 98765432 Record /
Rajkot PHY
Shah
Prof. Ajay 10
01234567 DBM Tuple
Surat
Patel 89 S
File Processing System
• In the earlier age the computer system was used to store business records
and produce different information. They were generally faster and more
accurate than equivalent manual systems.
• These systems stored groups of records in separate file and so they were
called file processing system.
• In a typical file processing systems, each department has its own files,
designed especially for those applications. The department itself works with
the data processing staff, sets policies or standards for the format and
maintenance of its files.
Disadvantages of File processing
system
1) Data redundancy
2) Data inconsistency
3) Difficulty in accessing data
4) Data isolation
5) Integrity problem
6) Atomicity problem
7) Concurrent access anomalies
8) Security problems
3 Level ANSI/SPARC Database
System
User User User
1 2 3
How data are View
View 1 View 2 View 3
viewed by each Level
users?
Conceptua
What data are stored Logic
l
and al
Level
What relationships Level
exist?
Database
• Internal level (Physical level)
• It describes how a data is stored on the storage device.
• Deals with physical storage of data.
• Structure of records on disk - files, pages, blocks and indexes and ordering of
records
• Internal view is described by the internal schema.
• Conceptual level (Logical level)
• What data are stored and what relationships exist among those data?
• It hides low level complexities of physical storage.
• For Example, STUDENT database may contain STUDENT and COURSE
tables which will be visible to users but users are unaware about their
storage.
• Database administrator works at this level to determine what data to keep
in the database.
• External level (View level)
• It describes only part of the entire database that an end user concern or
how data are viewed by each user.
• Different user needs different views of the database, so there can be many
views in a view level abstraction of the database. Used by end users and
application programmers.
• End users need to access only part of the database rather than the entire
database.
We are storing student information in a
student table.
User User User
User just interact with system with the help
1 2 3
of GUI. View
View 1 View 2 View 3
Users are not aware of how and what the Level
data is stored.
Records can be described as fields and
attributes along with their data types, their Conceptua
relationship among each other can be l Logic
logically implemented. Level al
Programmers generally work at this level. Level
Records can be described as blocks of
storage (bytes, gigabytes, terabytes etc.) in
Internal Physic
memory.
Level al
These details are often hidden from the
Level
programmers.
Database
Data Abstraction in DBMS
• Database systems are made-up of complex data structures.
• To ease the user interaction with database, the developers hide
internal irrelevant details from users.
• This process of hiding irrelevant details from user is called
data abstraction.
Levels of Abstraction
• Physical level describes how a record (e.g., customer) is stored.
• Logical level: describes data stored in database, and the relationships among
the data.
type customer = record
name : string;
street : string;
city : integer;
end;
• View level: application programs hide details of data types. Views can also
hide information (e.g., salary) for security purposes.
Mapping and Data
Independence Want to access some
data
User User User
1 2 3
View
View 1 View 2 View 3
Level
Reques
t
Process of transforming requests and results
Conceptua Logic
between the three levels is called mapping. l al
Level Level
Result
Database
Types of Data Independence
• Physical Data Independence
• Physical Data Independence is the ability to modify the physical schema
without requiring any change in logical (conceptual) schema and
application programs.
• Modifications at the internal levels are occasionally necessary to improve
performance.
• Possible modifications at internal levels are changes in file structures,
compression techniques, hashing algorithms, storage devices, etc.
CONTD..
• Logical Data Independence
• Logical data independence is the ability to modify the conceptual schema
without requiring any change in application programs.
• Modification at the logical levels is necessary whenever the logical
structure of the database is changed.
• Application programs are heavily dependent on logical structures of the
data they access. So any change in logical structure also requires
programs to change.
Types of Database Users
• Naive Users (End Users)
• Unsophisticated users who have zero knowledge of database system
• End user interacts to database via sophisticated software or tools
• e.g. Clerk in bank
• Application Programmers
• Programmers who write software using tools such as Java, .Net, PHP etc…
• e.g. Software developers
• Sophisticated Users
• Interact with database system without using an application program
• Use query tools like SQL
• e.g. Analyst
• Specialized Users (DBA)
• User write specialized database applications program
• Use administration tools
• e.g. Database Administrator
Role of DBA
(Database Administrator)
Role of DBA
• Schema Definition
• DBA defines the logical schema of the database.
• Storage Structure and Access Method Definition
• DBA decides how the data is to be represented in the database & how to access it.
• Defining Security and Integrity Constraints
• DBA decides on various security and integrity constraints.
• Granting of Authorization for Data Access
• DBA determines which user needs access to which part of the database.
• Liaison with Users
• DBA provide necessary data to the user.
CONTD..
• Assisting Application Programmer
• DBA provides assistance to application programmers to develop application
programs.
• Monitoring Performance
• DBA ensures that better performance is maintained by making a change in the
physical or logical schema if required.
• Backup and Recovery
• DBA backing up the database on some storage devices such as DVD, CD or magnetic
tape or remote servers and recover the system in case of failures, such as flood or
virus attack from this backup.
Database Architecture
• The design of a DBMS depends on its architecture. It can be
centralized or decentralized or hierarchical. The architecture of a
DBMS can be seen as either single tier or multi-tier. The tiers are
classified as follows :
• 1-tier architecture
• 2-tier architecture
• 3-tier architecture
• n-tier architecture
1-Tier Architecture
2-Tier Architecture
• The two-tier is based on Client Server architecture.
• The two-tier architecture is like client server application.
• The direct communication takes place between client and server.
• There is no intermediate between client and server.
2-Tier Architecture
3-Tier Architecture
• A 3-tier architecture separates its tiers from each other based on the
complexity of the users.
• How they use the data present in the database.
• It is the most widely used architecture to design a DBMS.
• This architecture has different usages with different applications.
• It can be used in web applications and distributed applications.
• The strength in particular is when using this architecture over
distributed systems.
3-Tier Architecture
Database (Data) Tier
• Database (Data) Tier − At this tier, the database resides along
with its query processing languages.
• We also have the relations that define the data and their
constraints at this level.
Application (Middle) Tier
• At this tier reside the application server and the programs that access the
database.
• For a user, this application tier presents an abstracted view of the database.
• End-users are unaware of any existence of the database beyond the application.
• At the other end, the database tier is not aware of any other user beyond the
application tier.
• Hence, the application layer sits in the middle and acts as a mediator between
the end-user and the database.
User (Presentation) Tier
• End-users operate on this tier and they know nothing about any
existence of the database beyond this layer.
• At this layer, multiple views of the database can be provided by
the application.
• All views are generated by applications that reside in the
application tier.
Database System Architecture
Naive Application Sophisticated Database
user programmer user administrator
writ
uses uses uses
e
Application Application Query Administration
interfaces program tool tool
Translates
Interprets
DML
DDL
Compiler DML DDL statements
Deals with
Executes low
statements
and linker queries interpreter into low
execution level
Application a set of
intolevel of
instructions
DDL and
instructions
tables
program DML compiler that the query
DML
generated
containing by
object code and organizer evaluation
Query evaluation Query statements
DML compiler.
metadata
engine engine
processor
understands
Buffer File Authorization and Transaction
manager manager integrity manager manager
Storage
Manages Provides
Fetches data
allocation of manager
Preserves
Checks the
interface
from disk storage
space on disk atomicity and
authoritylow-
between of
to memory
storage for
To provide faster Indices Data dictionary userscontrols
to data
level access
being used Disk storage
access to data concurrency
data and
stored and
Data Statistical data To To
store statistical
store
To storeitems
user data integrity
application
information
metadataabout the constraints
program or
data
queries
Database Languages
• Two main languages are Provided by DBMS :-
a)DDL (Data Definition Language)
b)DML (Data Manipulation Language)
• Data Definition Language:-To setup ,change and remove the data structure
from the table. Used to Create ,remove and alter the structure of the
database.
• Hierarchical Model
• Network Model
• Entity-relationship Model
• Relational Model
Hierarchical Model
Network Model
Entity-relationship Model
Relational Model
Professo
Student
r
• The hierarchy starts from the Root data, and expands like a tree,
adding child nodes to the parent nodes.
• In hierarchical model, data is organized into tree-like structure with
one-to-many relationship between two different types of data, for
example, one department can have many professors and many
students.
Hierarchical Model
Disadvantages
• Hierarchical model is Complex.
• One parent per child is allowed in hierarchical model.
• Data must be organized in a hierarchical fashion and it is done
without compromising the information.
• There is a Lack of structural independence in hierarchical model.
• Navigation system is complex in in hierarchical model.
• In Hierarchical model, Data is independent.
• Hierarchical model does not support Many too many relationships.
Network Model
• This is an extension of the Hierarchical model. In this model data
is organised more like a graph, and are allowed to have more
than one parent node.
B C
D E F
CONTD..
Advantages of the network model
• It is fast data access with a network model.
• The network model allows creating more complex and more strong queries as
compared to the database with a hierarchical database model. A user can
execute a variety of database queries when selecting the network model.
Disadvantages of a network model
• The network model is a very complex database model, so the user must be very
familiar with the overall structure of the database.
• Updating inside this database is a quite difficult and boring task. We need the
help of the application programs that is being used to navigate the data.
• In this model, data is organized in two-dimensional tables and the
relationship is maintained by storing a common attribute.
Rn Student_Na Ag SubI Subject_Na Teach
o me e D me er
10 1 DBMS Doshi
Raj Patel 20
1
10 Foreign Foreign2 DS Vyash
Meet
Key Shah 21 Key
2
SubI Mar
ResID Rno
D ks
1 101 1 80
2 101 2 85
3 102 1 75
4 102 2 80
Hierarchical Data Model Network Data Model Relational Data Model
1.Relationship between records is represented by
1. Relationship between records is of the 1. Relationship between records is expressed in
a relation that contains a key for each record
parent child type. the form of pointers or links.
involved in the relationship.
2. Many to many relationship cannot be 2. Many to many relationship can also be 2. Many to many relationship can be easily
expressed in this model implemented in this model implemented.
3. It is a simple, straightforward and natural
3.Record relationship implementation is quite 3. Relationship implementation is very easy
method of implementing record
complex due to the use of pointers. through the use of a key or composite key field.
relationships.
4. This type of model is useful only when 4. Relational model is useful for representing
4. Network model is useful for representing such
there is some hierarchical character in the most of the real world objects and relationships
records which have many to many relationships.
database. among them.
Symbo
l
Entitie
Branch Sem Author Price
s
Each and every entity must have one primary
key attribute.
Relationship between 2 entities is called binary
relationship.
Ternary Relationship
ProjectI Project
D Name
Project
Guid
Faculty Student
e
Technolo
Branch Branch Sem
gy
Multiple
Value Phone Birth
Date Area
No
Descriptive Attribute
• Attributes of the relationship is called descriptive attribute.
Descripti
ve
Attribute
Issue
BookN
RollNo Name Date Name
o
borro
customer loan
A1 B1 w
L
C1
1
A2 B2 L
C2
2
L
C3
A B 3
borro
customer loan
A1 B1 w
L
C1
1
A2 B2 L
C2
2
L
C3
A B 3
L
4
borro
customer loan
A1 B1 w
L
C1
1
A2 B2 L
C2
2
L
C3
A B 3
C4
borro
customer loan
A1 B1 w
C L
1 1
A2 B2 C L
2 2
C L
A B 3 3
C L
4 4
Weak
Strong Entity Weak
Entity Set Relationsh Entity Set
ip
Saving_Accou Current_Acco
nt unt
Sub
Class
Generalization v/s Specialization
Generalization Specialization
It splits an entity to form
It extracts the common features
multiple new entities that inherit
of multiple entities to form a new
some feature of the splitting
entity.
Nam Addre
entity. Nam Addre
e ss e ss
Sala
SPI
Person Person ry
Nam Nam
e e IS
Addre IS
A Addre A
ss ss
Top-down
approach
Bottom-up
approach
Sala Sala
SPI SPI
ry ry
Generalization v/s Specialization
Generalization Specialization
The process of creation of group The process of creation of sub-
from various entities is called groups within an entity is called
generalization.
It is Bottom-up approach. specialization.
It is Top-down approach.
The process of taking the union of The process of taking a sub set of
two or more lower level entity higher level entity set to form a
sets to produce a higher level entity lower level entity set.
set.
It starts from the number of entity It starts from a single entity set and
sets and creates high level entity set creates different low level entity sets
using some common features. using some different features.
Generalization & Specialization example
Nam Addre
e ss
PID City
Person
IS
A
Sala Balan
Employee Customer
ry ce
IS
A
Days Hour
Worked Worked
Limitation of E-R diagram
• In E-R model we cannot express relationships between two
relationships.
Relatio Relatio Relatio
n1 n n2
Relatio
Entity 1 Entity 2
n
Limitation of E-R diagram
Custom
Company
er
Work
Employee Department
s
Customer
Can not connect two
relationship
Borro
Borrow
w
Loan Loan
Medical Admitt
Has Patient Hospital
Record ed
Report
IS Tr e Has
Name ats
A
Indoo Outdo
r or Doctor
Room
No
IPDID OPDID Dr
DrID
Char Name
ge
Reduce the E-R diagram to database schema
Step 1: Reduce Entities and Simple
Attributes: PersonI
Name
An entity of an ER diagram is turned D
into a table.
Person
Each attribute (except multi-valued
attribute) turns into a column (attribute) Addres
City
in the table. s
Phone
Table name can be same as entity name. No
Key attribute of the entity is the primary
key of the table which is usually Person (PersonID, Name,
underlined. Address, City)
Cardinality:
Wife
Convert both entities in to table with
proper attribute.
Having
Place the primary key of any one table
in to the another table as a foreign key. Person
Place the primary key of the Wife table
PersonI
WifeID in the table Persons as Foreign key. D
PName
Cardinality:
House
Convert both entities in to table with
proper attribute.
Having
Place the primary key of table having 1
mapping in to the another table having Person
many cardinality as a Foreign key.
Place the primary key of the Person table PersonI
PName
D
PersonID in the table House as Foreign Person (PersonID, PName)
key. House (HouseID, Hname,
PersonID)
Reduce the E-R diagram to database schema
Balanc
ActNo
Step 5: Reduce N:N Mapping e
Cardinality:
Account
Convert both entities in to table with
proper attribute. Has_Ac
Create ct
a separate table for
relationship. Customer
Place the primary key of both entities
CNam
table into the relationship’s table as CID
e
foreign key. Customer (CID, CName)
Place the primary key of the Customer Account (ActNo, Balance)
Has_Acct (HasAcctID, CID,
table CID and Account table Ano in the ActNo)
table Has_Acct as Foreign key.
Symbols used in E-R diagram