0% found this document useful (0 votes)
2 views108 pages

Unit 1 DBMS

This document provides an overview of Database Management Systems (DBMS), covering concepts such as data, information, and the advantages and disadvantages of using DBMS. It discusses various data models, the architecture of database systems, and the importance of data integrity, redundancy reduction, and user access control. Additionally, it highlights the limitations of manual methods and the need for efficient data storage and management in various applications.

Uploaded by

harshjhawar74
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views108 pages

Unit 1 DBMS

This document provides an overview of Database Management Systems (DBMS), covering concepts such as data, information, and the advantages and disadvantages of using DBMS. It discusses various data models, the architecture of database systems, and the importance of data integrity, redundancy reduction, and user access control. Additionally, it highlights the limitations of manual methods and the need for efficient data storage and management in various applications.

Uploaded by

harshjhawar74
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

UNIT 1

DATABASE MANAGEMENT SYSTEMS


Unit I (Syllabus)
DBMS Concepts and architecture Introduction, Database approach
v/s Traditional file accessing approach, Advantages, of database
systems, Data models, Schemas and instances, Data independence,
Data Base Language and interfaces, Overall Database Structure,
Functions of DBA and designer, ER data model: Entitles and
attributes, Entity types, Defining the E-R diagram, Concept of
Generalization, Aggregation and Specialization. transforming ER
diagram into the tables. Various other data models object oriented
data Model, Network data model, and Relational data model,
Comparison between the three types of models
Contents
• Introduction
• Database Applications
• Limitations of Manual Methods
• Need to Store Data
• Purpose of Database Systems
• File Processing System
• Database Approach
• Database system Architecture
Introduction
• Data :-Fact that can be recorded or stored.
e.g. Person Name, Age, Gender and Weight.
• Information:-Processed data. Backbone of any organization.
• Database:-Collection of logically related data.
e.g. Books Database in Library, Student Database in University.
• Management - Manipulation, Searching and Security of data.
e.g. Viewing result in RGPV website, Searching exam papers in
RGPV website
CONTD..
• System - Programs or tools used to manage database.
e.g. SQL Server Studio Express, Oracle.
• DBMS - A Database Management System is a software for
creating and managing databases.
• Database Management System (DBMS) is a software designed
to define, manipulate, retrieve and manage data in a database.
e.g. MS SQL Server, Oracle, My SQL, SQLite, MongoDB
CONTD..
• Database Management System
- Set of Programs to access data.
- Contains information about particular enterprise.
- Provides Environment that is both efficient and convenient.
• DBMS is a computerized record-keeping system.
• DBMS is required where ever data need to be stored.
Applications of DBMS
1.e-commerce (Flipkart, Amazon, Shopcules, eBay )
2.Online Television Streaming (Hotstar, Amazon Prime)
3.Social Media (WhatsApp, Facebook, Twitter, Linkedin)
4.Banking & Insurance
5.Airline & Railway
6.Universities and Colleges/Schools
7.Library Management System
8.Human Resource Department
9.Hospitals and Medical Stores
10.Government Organizations
Need to store data
• Data originates at one time and used later.
• Governmental regulations requires access to past data.
• Data used later for auditing, evaluation purpose.
• Used more than once : save for future use.
Limitations of Manual Methods
• Speed
• Accuracy
• Consistency and reliability
• Poor response time
• Work-load handling capability
• ad hoc information needs
• Cost
• Irregularity
• Difficulties in handling big tasks
Advantages of DBMS
Reduce data redundancy
Computer (duplication) Civil
Addre Mobi Subje Addre Mobi Subje
Emp_Name Emp_Name
ss le ct ss le ct
Prof. Ankit Math Prof. Ankit Math
Pune 1234 Pune 1234
Roy s Roy s

Database management Same data is


system can remove such stored at
data redundancy by storing four different
data centrally. places.

Addre Mobi Subje Addre Mobi Subje


Emp_Name Emp_Name
ss le ct ss le ct
Prof. Ankit Math Prof. Ankit Math
Pune 1234 Pune 1234
Roy s Roy s
Electrical Mechanical
Remove data inconsistency
Computer Civil

Addre Mobi Subje Addre Mobi Subje


Emp_Name Emp_Name
ss le ct ss le ct
Prof. Ankit 1234 Math Prof. Ankit Math
Pune Pune 1234
Roy 56 s Roy s
Database management Mobile number Same data having
system keep data in Changed different
consistent state states

Addre Mobi Subje Addre Mobi Subje


Emp_Name Emp_Name
ss le ct ss le ct
Prof. Ankit 1234 Math Prof. Ankit Math
Pune Pune 1234
Roy 56 s Roy s
Electrical Mechanical
Data isolation
• Data are scattered in various files.
• Files may be in different formats.
• DBMS allow us to access (retrieve) appropriate data easily.
• Data isolation is a property that determines when and how
changes made by one operation become visible to other
concurrent users and systems.
• This issue occurs in a concurrency situation.
Data isolation
File -
1
Emp_Name Address Mobile Subject
Prof. Ankit
Pune 1234 PPS
Roy
File -
2
Emp_Name Post Salary Load
Professo
Prof. Ankit Roy 50,000 15
r
File -
3 Ratin
Emp_Name Teaching Knowledge
g
Prof. Ankit Roy Good Excellent 9
Guaranteed atomicity

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

• DBMS allows us to implement such business rules in


our database
Want to
access
Computer Civil

Addre Mobi Subje Addre Mobi Subje


Emp_Name Emp_Name
ss le ct ss le ct
Prof. Ajay Prof. Ajay
Rajkot 1234 PPS Rajkot 1234 PPS
Shah Shah
Database management
Want to system allows more than
access one user to access same
data simultaneously.

Addre Mobi Subje Addre Mobi Subje


Emp_Name Emp_Name
ss le ct ss le ct
Prof. Ajay Prof. Ajay
Rajkot 1234 PPS Rajkot 1234 PPS
Shah Shah
Electrical Mechanical

Sharing of data among multiple users.


File -
1 Addre Mobil Subje
Emp_Name
ss e ct
Prof. Ankit
Pune 1234 PPS
Roy Wants
to USER1
File -
access
2 Salar
Emp_Name Post Load
y
Prof. Ankit Lectur 50,00
15 Wants
Roy er 0
to USER
File - access 2
3 Teachi Knowled Rati
Emp_Name
ng ge ng
Prof. Ankit
Good Excellent 9
Roy
DBMS prevents unauthorized user to
access data.
Provides facilities to backup and restore the database
in case of failure.
Advantages of DBMS (Summary)
• Reduce data redundancy (duplication)
• Avoids unnecessary duplication of data by storing data centrally.
• Remove data inconsistency
• By eliminating redundancy, data inconsistency can be removed.
• Data isolation
• A user can easily retrieve proper data as per his/her requirement.
• Guaranteed atomicity
• Either transaction executes 0% or 100%.
Advantages of DBMS (Summary)
• Allow implementing integrity constraints
• Business rules can be implemented such as do not allow to store amount less than
Rs. 0 in balance.
• Sharing of data among multiple users
• More than one users can access same data at the same time.
• Restricting unauthorized access to data
• A user can only access data which is authorized to him/her.
• Providing backup and recovery services
• Can take a regular auto or manual backup and use it to restore the database if it
corrupts.
Disadvantages of DBMS
• Cost :-Hardware and software
• Complexity:- Operation of DBMS and users.
• Danger of Overkill:- For single users Database is not advisable
• Lower Efficiency:- Processing overhead (implement security,
integrity and overhead)
Database
• Logically coherent collection of data with some inherent
meaning.
• Elements of database:-
• Data
• Relationship
• Constraints
• Schema
Basic Terms
• Data
• Data is raw, unorganized facts that need to be processed.
• Example: Marks of students
• Student_1 = 50/100, Student_2 = 25/100.
• Information
• When data is processed, organized, structured or presented in a given context
so as to make it useful, it is called information.
• Example: Result of students (Pass or Fail)
• Student_1 = Pass, Student_2 = Fail.
• Metadata
• Metadata is data about data.
• Data such as table name, column name, data type, authorized user and
user access privileges for any table is called metadata for that table.
Facul
ty Addre Mobile_N Subje
Emp_Name
ss o ct
Prof. Ajay 98765432 Physi
Rajkot
Shah 10 cs
• Metadata of above table is:
• Table name such as Faculty
• Column name such as Emp_Name, Address, Mobile_No, Subject
• Datatype such as Varchar, Decimal
• Access privileges such as Read, Write (Update)
• Data dictionary
• A data dictionary is an information repository which contains metadata.
• Table Name – Faculty
• Column Name – EmpName, Address, Mob,
Subject, Salary
• Datatype – Varchar, Decimal
• Access Privileges – Read, Write (Update)
• Data warehouse
• A data warehouse is an information repository which stores data.

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?

How the data are Internal Physic


actually stored on Level al
storage devices? Level

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

Ability to modify a schema definition in one


level without affecting a schema definition in Internal Physic
the next higher level. Level al
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.

• DDL commands a)Create b)Alter c)Drop d)Rename d)Truncate


Database Languages
• Data Manipulation Language:- a)Insert b)Update c)Delete
d)Merge

• Data Manipulation Operation is called query.

• A DML is a statement that request the retrieval of information.


Database Models
• A Database model defines the logical design and structure of a database and
defines how data will be stored, accessed and updated in a database
management system. While the Relational Model is the most widely used
database model, there are other models too:

• Hierarchical Model
• Network Model
• Entity-relationship Model
• Relational Model
Hierarchical Model

Network Model

Entity-relationship Model

Relational Model

Object-oriented database Model


Object Based Model
• Describes data at conceptual and view levels
• Provide flexible structure.
• Allow one to specify data constraints explicitly.
• Model emphasizes that everything is object, having a set of
attributes
Record Based Model
• Describes data at conceptual and view levels
• Provided higher level description of implementation
• Database is structured in fixed format records of several types.
• Each field is usually of fixed length.
Physical Data Model
• Describe data at lowest level.
• Describe the way DBMS is going to use secondary storage
device.
• Describe the way data and data relationships are
maintained.
• The hierarchical model organizes data into a tree-like structure,
where each record has a single parent or root.
Departm
ent

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.

• In this database model data is more related as more relationships


are established in this database model.
Network Model

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.

5. Searching for a record is very difficult


5. Searching for a record is easy since there are 5. A unique, indexed key field is used to search
since one can retrieve a child only after
multiple access paths to a data element. for a data element.
going through its parent record.
6. Relational model does not maintain physical
6. In Hierarchical model record relations are connection among records, data is organized
6.In Network model record relations are physical.
physical. logically in the form of rows and columns and
stored in table.
7. Data integrity maintaining methods like
7. During updation or deletion process, 7. No problem of inconsistency exists in Network
Normalization process are adopted for
chances of data inconsistency is involved. model.
consistency.
Basic concept of E-R
diagram
• What is Database Design?
• Database Design is a collection of processes that facilitate the designing,
development, implementation and maintenance of enterprise database
management systems.

• What is E-R diagram?


• E-R diagram: (Entity-Relationship diagram)
• It is graphical (pictorial) representation of database.
• It uses different types of symbols to represent different objects of
database.
Entity
• An entity is a person, a place or an object. Entity
• An entity is represented by a rectangle which contains the nameName
of an
entity. Symbo
l
• Entities of a college database are:
• Student
• Professor/Faculty
Student Faculty Course
• Course
• Department
• Result
• Class
• Subject
Exerci Write down the different entities of bank
se database.
Exerci Write down the different entities of hospital
se database.
Entity Set
• It is a set (group) of entities of same type.
• Examples:
• All persons having an account in a bank
• All the students studying in a college
• All the professors working in a college
• Set of all accounts in a bank
Attributes
• Attribute is properties or details about an entity. Attribute
Name
• An attribute is represented by an oval containing name of an attribute.
Symbo
• Attributes of Student are: l
• Roll No
RollNo Name
• Student Name
• Branch
• Semester Student
• Address
• Mobile No
• Age
• SPI
• Backlogs
Relationship
• Relationship is an association (connection) between several entities.
• It should be placed between two entities and a line connecting it to an
entity.
• A relationship is represented by a diamond containing relationship's
name. Relationshi
p Name

Symbo
l

Student Issue Book


E-R Diagram of a Library System
Primary Primary
Key Attribut Key
es
RollNo Name Relations BookN
Name
o
hip

Student Issue Book

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

FacID Name RollNo Name

Guid
Faculty Student
e

Technolo
Branch Branch Sem
gy

Relationship between 3 entities is called


ternary relationship.
Types of Attributes
• Simple Attribute
• Composite Attribute
• Single valued Attribute
• Multi Valued Attribute
• Base Attribute
• Derived Attribute
Types of Attributes
• Simple attributes are those attributes which can not be divided further.
• Composite attributes are those attributes which are composed of many
other simple attributes.
• Single valued attributes are those attributes which can take only one
value for a given entity from an entity set.
• Multi valued attributes are those attributes which can take more than
one value for a given entity from an entity set.
• Derived attributes are those attributes which can be derived from other
attribute(s).
Entity with all Types of
Single
Attributes
Middle
Value Name
First Last
Name Name
Simple
Composi Apartme
RollNo Name te nt
Composi
Derived
te

Age Student Address Street

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

Student Issue Book

Branch Sem Author Price


Role
• Roles are indicated by labeling the lines that connect diamon
(relationship) to
rectangles (entity).
• The labels “Coordinator” and “Head” are called roles; they speci
Faculty entities
interact with whom via Reports_To relationship set.
EmpID Name
• Role labels are optional, and are used to clarify semantics (meaning)
the relationship.
Coordinat Reports_T
Faculty or o
Hea
d
Experien
Branch
ce
Mapping Cardinality (Cardinality
Constraints)
• It represents the number of entities of another entity set which are
connected to an entity using a relationship set.
• It is most useful in describing binary relationship sets.
• 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 relationship (1 – 1)
• An entity in A is associated with only one entity in B and an entity in
B is associated with only one entity in A.

borro
customer loan
A1 B1 w
L
C1
1
A2 B2 L
C2
2
L
C3
A B 3

• Example: A customer is connected with only one loan using the


relationship borrower and a loan is connected with only one
customer using borrower.
One-to-Many relationship (1 – N)
• An entity in A is associated with more than one entities in B and an
entity in B is associated with only one entity in A.

borro
customer loan
A1 B1 w
L
C1
1
A2 B2 L
C2
2
L
C3
A B 3
L
4

• Example: A loan is connected with only one customer using borrower


and a customer is connected with more than one loans using
borrower.
Many-to-One relationship (N – 1)
• An entity in A is associated with only one entity in B and an entity in
B is associated with more than one entities in A.

borro
customer loan
A1 B1 w
L
C1
1
A2 B2 L
C2
2
L
C3
A B 3
C4

• Example: A loan is connected with more than one customer using


borrower and a customer is connected with only one loan using
borrower.
Many-to-Many relationship (N – N)
• An entity in A is associated with more than one entities in B and an
entity in B is associated with more than one entities in A.

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

• Example: A customer is connected with more than one loan using


borrower and a loan is connected with more than one customer
using borrower.
Weak Entity Set
• An entity set that does not have a primary key is called weak entity
set. Payment-
date
loan- amoun payment- Payment-
no t no amount

loan L_P payment

Weak
Strong Entity Weak
Entity Set Relationsh Entity Set
ip

• Weak entity set is indicated by double


rectangle.
• Weak entity relationship set is indicated by
double diamond.
Superclass v/s Subclass
Super Class Sub Class
A superclass is an entity from which A subclass is an entity that is
another entities can be derived. derived from another entity.
E.g, E.g,
an entity account has two subsets saving_account and current_account
saving_account and current_account entities are derived from entity
So an account is superclass. account.
So saving_account and
current_account are subclass.
Account Super
Class

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

Student Faculty Student Faculty

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

Full Time Part Time

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

Process of creating an entity by combining various


components of E-R diagram is called aggregation.
E-R diagram of Hospital Management
System
MRID
PatID Name HosID Name

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)

 It is highly recommended that every table


should start with its primary key attribute
conventionally named as TablenameID.
Reduce the E-R diagram to database schema
Step 2: Reduce Multi-valued PersonI Phone
No
D
Attributes:
 Multi-value attribute is turned into a Person
new table.
PhoneNo (PhoneID, PersonID,
 Add the primary key column into multi- PhoneNo)
value attribute’s table.
Foreign
 Add the primary key column of the Key
Person (T1)

parent entity’s table as a foreign key


within the new (multi-value attribute’s) Having
table.
 Then make a 1:N relationship between PhoneNo (T2)
the Person table and PhoneNo table.
Reduce the E-R diagram to database schema
WNam
WifeID
Step 3: Reduce 1:1 Mapping e

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

OR Person (PersonID, PName)


 Place the primary key of the Person table Wife (WifeID, Wname, PersonID)
PersonID in the table Wife as Foreign key. Wife (WifeID, Wname)
Person (PersonID, Pname,
WifeID)
Reduce the E-R diagram to database schema
HouseI
HName
Step 4: Reduce 1:N Mapping D

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

Customer Name Hold


Entity Attribute Relations
hip
PhoneN
EmpID Age
o
Primary Derive Multi
Key d Valued
Attribute Attribu Attribute
Payment te
PymtID Issue

Weak Discriminat Weak


Entity ing Entity
Attribute
Role Relations
Nam
hip
E R E e R ISA

Total Role Specializati


Participat Indicator on/
ion Generalizat
ion
Integrity Constraints
 Integrity constraints are a set of rules. It is used to maintain the
quality of information.
 Integrity constraints ensure that the data insertion, updating, and other
processes have to be performed in such a way that data integrity is not
affected.
 Thus, integrity constraint is used to guard against accidental damage
to the database.
 Various Integrity Constraints are:
 Check
 Not null
 Unique
 Primary key
 Foreign key
Integrity Constraints
 Check
 This constraint defines a business rule on a column. All the rows in that column must
satisfy this rule.
 Limits the data values of variables to a specific set, range, or list of values.
 The constraint can be applied for a single column or a group of columns.
 E.g. value of SPI should be between 0 to 10.
 Not null
 This constraint ensures all rows in the table contain a definite value for the column
which is specified as not null. Which means a null value is not allowed.
 E.g. name column should have some value.
 Unique
 This constraint ensures that a column or a group of columns in each row have a
distinct (unique) value.
 A column(s) can have a null value but the values cannot be duplicated.
 E.g. enrollmentno column should have unique value.
Integrity Constraints
 Primary key
 This constraint defines a column or combination of columns which uniquely identifies
each row in the table.
 Primary key = Unique key + Not null
 E.g. enrollmentno column should have unique value as well as can’t be null.
 Foreign key (referential integrity constraint)
 A referential integrity constraint (foreign key) is specified between two tables.
 In the referential integrity constraints, if a foreign key column in table 1 refers to the
primary key column of table 2, then every value of the foreign key column in table 1
must be null or be available in primary key column of table 2.
Foreign Key

Dept Dept_Na Roll Student_N Dept


HOD
ID me No ame ID
Comput 101 Raj Patel 1
1 Doshi
er
102 Meet Shah 2
Vyas
2 IT
h

You might also like