Download as pdf or txt
Download as pdf or txt
You are on page 1of 111

DBMS

Unit-2
Database Design, Architecture and
Model

7 hours, 12 marks

Sr. Lec. Sujan Shrestha


9801104103
sujan.shrestha@kecktm.edu.np
 Outline
Looping
• Level database Architecture
• Overview of the database designing process and view
of data
• Data models: Hierarchical, Network, Relational, ER-
model, Object Base Data Model
• ER Diagram: concepts, Entity Relationships Diagram,
Weak Entity sets, Strong entity sets, Aggregation,
Generalization, Converting ER-Diagram
Database Architectures

 In 1971, DBTG (Database Task Group) recognised need for two-level


approach to a database architecture
 i.e. schema (system view) and sub-schemas (user views)
 In 1975, ANSI Standards Planning and Requirements Committee produced
a similar architecture and terminology
 Based on previous proposals from IBM
 But recognised
 need for 3 levels
 implementation independent layer separating programs from physical detail
 and a system catalogue
 Never became a standard
 But provides basis for functionality of DBMS
Slide 3
ANSI-SPARC Database System Architecture

 The ANSI SPARC (1975) architecture specifies 3 levels


 External – user views of the data
 Conceptual – the ‘data model’ view of the data
 Internal – how the data is physically stored
 The data model should NOT incorporate any physical
characteristics
 Incorporates External and Conceptual Level and mapping between
 i.e. the data model sits at the conceptual (and external) level
 there are of course physical data models

Slide 4
Database System Architecture

Host language Host language Host language


+Data sublanguage +Data sublanguage +Data sublanguage

External External External


View 1 View 2 View n

Conceptual DBMS
Level

Internal
Level
Slide 5
Objectives of Three Level Architecture

 “to separate each user’s view of the database from the way the database
is physically represented” (Connolly and Begg)
 To provide data independence. Two kinds:
 Logical: “immunity of external schemas to changes in conceptual schema”
 Physical: “immunity of conceptual schema to changes in internal schema”
 Why bother?
 Each user accessing same data but given customised view of it
 User’s interaction with data is independent of how it is stored
 DBA can change storage details without affecting users’ views
 Internal structure of db unaffected by change to new storage device
 DBA can change conceptual structure without affecting all users

Slide 6
Schema

 External Schema – definitions of the various external record


types in that external view
 Conceptual Schema – definitions of the various conceptual
record types
 Internal Schema – stored record types, indexes, physical
sequences of stored data
 Written using DDL
 data definition language
 Database queried using DML
 data manipulation language
Slide 7
External Level

 aka User Level


 The individual user level
 Can be an application program or an end user
 Each user has a language at his/her disposal
 Application programmers, e.g. Java, VB.NET
 End users, e.g. SQL

 a data sublanguage normally embedded in host language (not


necessarily indistinct)
 With 2 elements DML and DDL
 Each external view is defined by means of an external schema

Slide 8
Conceptual Level

 aka Community Logical Level


 Conceptual view is an abstract representation of the entire information
concept of the database
 Defined by conceptual schema
 Which is defined by conceptual DDL

Slide 9
Internal Level

 aka Storage Level


 Low-level representation of the database
 Uses stored records
 Internal records are described by internal schema
 Written in internal DDL
 e.g. CREATE INDEX etc.

Slide 10
Data Dictionary

 As well as being able to query the data


 Want also to be able to query ‘data about the data’
 known as metadata
 e.g. the schema, security, integrity constraints…
 The database keeps a data dictionary which we can query which contains all
of this data
 In Oracle, two commands that you can use are:
 describe prop_for_rent;
 select * from tab;

Slide
11
Data Models

 A data model is a (formal) way of representing data


 e.g. relational model
 network model
 hierarchical model
 there are others which we will meet during the module
 SQL is NOT a data model, and neither is SQLServer!
 SQL is a query language
 SQL Server is a database management system

Slide
12
Data Model

 Definition by Codd (1981), paraphrased by Date:

 ‘A data model is an abstract, self contained,


logical definition of the objects, operators,
and so forth, that together constitute the
abstract machine with which users interact.
The objects allow us to model the structure of
the data. The operators allow us to model its
behaviour.’
Slide
13
Data Models

 Data Model = Structure + Rules + Manipulation


 Structure
 The concepts in our data model that are available to ‘store’ the data, e.g. tables
 Rules
 Constraints which can be applied to the data to maintain integrity, e.g. primary
key
 Manipulation
 Query language to create, delete, update and retrieve the data, e.g. SQL,
relational algebra, OQL

Slide
14
What and Why data modeling?

 Data modeling: It is a process of creating a data model for the data to be


stored in a Database i.e. a conceptual representation of
- Data objects
- The associations between different data objects
- The rules
 Data modeling helps in the visual representation of data and enforces
business rules, regulatory compliances, and government policies on the data.
Data Models ensures consistency in naming conventions, default values,
semantics, security while ensuring quality of the data.
 Data model emphasizes on (1) what data is needed and (2) how it should be
organized instead of what operations need to be performed on the data.
 Data Models : Simple representations of complex real-world data structures.
 Useful for supporting a specific problem domain
 Model – Abstraction of a real-world object or event.
Primary goal of using data model are:

 A data model helps design the database at the logical levels.


 Data Model structure helps to define the relational tables, primary and
foreign keys and stored procedures.
 It provides a clear picture of the base data and can be used by database
developers to create a physical database.
 It is also helpful to identify missing and redundant data.
 Though the initial creation of data model is labor and time consuming, in the
long run it makes your IT infrastructure upgrade and maintenance cheaper
and faster.
Data Model layers

 View: This Data Model defines WHAT the system contains. This model is
typically created by Business stakeholders and Data Architects. The purpose is
to organize, scope and define business concepts and rules.
 Logical: Defines HOW the system should be implemented regardless of the
DBMS. This model is typically created by the Data Architects and Business
Analysts. The purpose is to developed technical map of rules and data
structures.
 Physical: This Data Model describe HOW the system will be implemented using
a specific DBMS system. This model is typically created by DB Administrators
and developers. The purpose is actual implementation of the database.
Data Model Basic building Blocks
 Entity : Unique and distinct object used to collect and store data
 Attribute: Characteristic of an entity
 Relationship: Describes an association among entities
 One-to-one: When only a single instance of an entity is associated with the relationship, it is termed as
‘1:1’.
 One-to-many: When more than one instance of an entity is related and linked with a relationship, it is
termed as ‘1:N’.
 Many-to-one: When more than one instance of an entity is linked with the relationship, it is termed as
‘N:1’.
 Many-to-many: When more than one instance of an entity on the left and more than one instance of an
entity on the right can be linked with the relationship, then it is termed as N:N relationship.

 Constraints: Set of rules to ensure data integrity


Data Models Types

 Some popular data models in database systems:


 Network
 Hierarchical
 ER model
 Relational
 Object-oriented
 These are all examples of a Conceptual Model
 i.e. how the user sees the data

Slide 20
Hierarchical Models
 Manage large amounts of data for complex manufacturing
projects
 Represented by an upside-down tree which contains
segments
 Segments: Equivalent of a file system’s record type
 Depicts a set of one-to-many relationships
 Advantages
 Promotes data sharing
 Parent/child relationship promotes conceptual simplicity and data integrity
 Database security is provided and enforced by DBMS
 Efficient with 1:M relationships
 Disadvantages
 Requires knowledge of physical data storage characteristics
 Lack of standards
 Change in structure require changes in all application programs
Network Database Model

 Represents complex data relationships


 Improve database performances and impose a database standard
 Depicts both one-to-many (1:M) and many to many (M:N) relationships
 Advantages
 Conceptual simplicity
 Handles more relationship types
 Data access is flexible
 Disadvantages
 Navigational system yields complex implementation, application
development, and management
 Structural changes require changes in all application
Relational Model

 All the data is stored in various Tables


 Based on a relation
 Relation or table: Matrix composed of intersecting tuple and attribute
 Tuple: Rows or Records
 Attribute: Columns

Instructor Table
ID Name Dept_name Salary
1 Shree krishna Sulu Computer 145000
2 Sagun Manandhar Electronics 152000
3 Ravi Poudel Account 140000
4 Gaurav Gautam Electronics 145000
5 Dipen Manandhar Computer 125000
Relational Model example
Faculty Table
ID Name Dept_name Salary
1 Shree krishna Sulu Computer 145000
2 Sagun Manandhar Electronics 152000
3 Ravi Poudel Account 140000
4 Ravi Poudel Computer 140000
5 Gaurav Gautam Electronics 145000
6 Dipen Manandhar Computer 125000

Department Table
Dept_Name Building budget
Computer Block E 2500000
Electronics Block A 1500000
Account Block B 400000
Science and Block C 1500000
Humanities
Lab Block D 1350000
 Advantages
- Structural independence is promoted using independent tables
- Tabular view improves conceptual simplicity
- Isolates the end user from physical-level details
 Disadvantages
- Requires substantial hardware and system software overhead
Object oriented database model

 Object oriented database is a database that subscribes to a model with information represented
by Objects. Objects belong to certain class and object consists of attribute

Customer Class
Rajan Object

Address Phone No Item Price

Kathmandu 98……….. Jeans pant 2500


OODM RDM
Class Relation Table
Object instance tuple

Variable Attribute/ column


Basic concepts
 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.
 An entity is represented by a rectangle which contains the name of an entity. Entity Name

 Entities of a college database are:


Symbol
 Student
 Professor/Faculty
 Course
 Department
Student Faculty Course
 Result
 Class
 Subject

Exercise Write down the different entities of bank database.

Exercise Write down the different entities of hospital 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
 An attribute is represented by an oval containing name of an attribute. Name
 Attributes of Student are:
Symbol
 Roll No
 Student Name
RollNo Name
 Branch
 Semester
 Address
Student
 Mobile No
 Age
 SPI
 Backlogs
Exercise Write down the different attributes of Faculty entity.

Exercise Write down the different attributes of Account entity.


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.

Relationship
Name

Symbol

Student Issue Book


E-R Diagram of a Library System
Primary Primary
Key Attributes Key

RollNo Name BookNo Name


Relationship

Student Issue Book

Branch Sem Entities Author Price

Each and every entity must have one primary key attribute.
Relationship between 2 entities is called binary relationship.
Ternary Relationship
ProjectID Project Name

Project

FacID Name RollNo Name

Faculty Guide Student

Branch Technology Branch Sem

Relationship between 3 entities is called ternary relationship.


Exercise
 Draw an E-R diagram of following pair of entities
 Customer & Account
 Customer & Loan
 Doctor & Patient
 Student & Project
 Student & Teacher
 Note: Take four attributes per entity with one primary key attribute.

Keep proper relationship between two entities.


Types of Attributes

Simple Attribute Composite Attribute


Cannot be divided into subparts Can be divided into subparts
E.g. RollNo, CPI E.g. Name
(first name, middle name, last name)
Address
(street, road, city)

Symbol Symbol
Name

Roll No First name Last name

Middle name
Types of Attributes

Single-valued Attribute Multi-valued Attribute


Has single value Has multiple (more than one) value
E.g. RollNo, CPI E.g. PhoneNo
(person may have multiple phone nos)
EmailID
(person may have multiple emails)

Symbol Symbol

Roll No Phone No
Types of Attributes

Stored Attribute Derived Attribute


It’s value is stored manually in It’s value is derived or calculated
database from other attributes
E.g. Birthdate E.g. Age
(can be calculated using current date and
birthdate)

Symbol Symbol

Birthdate Age
Entity with all types of Attributes

Middle
Name
First Name Last Name
Single
Simple
Value
RollNo Name Composite Apartment
Derived Composite

Age Student Address Street

Multiple Stored
Value
Phone No Birth Date Area
Exercise
 Draw an E-R diagram of Banking Management System.
 Draw an E-R diagram of Hospital Management System.
 Draw an E-R diagram of College Management System.
 Take only 2 entities
 Keep proper relationship between two entities
 Use all types of attributes
Descriptive Attribute
 Attributes of the relationship is called descriptive attribute.

Descriptive
Attribute

Issue
RollNo Name Date BookNo Name

Student Issue Book

Branch Sem Author Price


Role
 Roles are indicated by labeling the lines that connect diamonds (relationship) to rectangles (entity).
 The labels “Coordinator” and “Head” are called roles; they specify Faculty entities interact with whom via
Reports_To relationship set.
 Role labels are optional, and are used to clarify semantics (meaning) of the relationship.

EmpID Name

Coordinator
Faculty Reports_To
Head

Branch Experience
Recursive Relationship Set
 The same entity participates in a relationship set more than once then it is called recursive relationship set.

FacID FName DeptID DName

Faculty Works Department

Post Recursive
Relationship
FName Post Set DName
Nabin Professor Prof. Computer
Sujan Professor Civil
Sudeep HOD Mechanical
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.

customer borrow loan


A1 B1
C1 L1
A2 B2
C2 L2

C3 L3
A B

 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.

customer borrow loan


A1 B1
C1 L1

A2 B2 C2 L2

C3 L3
A B
L4

 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.

customer borrow loan


A1 B1
C1 L1

A2 B2 C2 L2

C3 L3
A B
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 (M – 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.

customer borrow loan


A1 B1
C1 L1
A2 B2
C2 L2

C3 L3
A B
C4 L4

 Example: A customer is connected with more than one loan using borrower and a loan is
connected with more than one customer using borrower.
Mapping Cardinality (Cardinality Constraints)
[Exercise]
 Draw an E-R diagram and specify which type of mapping cardinality will be there in the
following examples:
 Each customer has only one account in the bank and each account is held by only one customer.
[single account]
 Each customer has only one account in the bank but an account can be held by more than one
customer. [joint account]
 A customer may have more than one account in the bank but each account is held by only one
customer. [multiple accounts]
 A customer may have more than one account in the bank and each account is held by more
than one customer. [join account as well as multiple accounts]
 A student can work in more than one project and a project can be done by more than one
student.
 A student can issue more than one book but a book is issued to only one student.
 A subject is taught by more than one faculty and a faculty can teach more than one subject.
Participation Constraints
 It specifies the participation of an entity set in a relationship set.
 There are two types participation constraints
 Total participation
 Partial participation

Partial participation Total participation


• some entities in the entity set may not • every entity in the entity set participates in
participate in any relationship in the at least one relationship in the relationship
relationship set. set.
• indicated by single line • indicated by double line

customer borrow loan

C1 L1

C2 L2

C3
Weak Entity Set
 An entity set that does not have a primary key is called weak entity set.

Payment-
date
amount Payment-
loan-no payment-no
amount

loan L_P payment

Strong Weak Entity Weak Entity


Entity Set Relationship Set

• Weak entity set is indicated by double rectangle.


• Weak entity relationship set is indicated by double
diamond.
Weak Entity Set
 The existence of a weak entity set depends on the existence of a strong entity
set.
 The discriminator (partial key) of a weak entity set is the set of attributes that
distinguishes all the entities of a weak entity set.
 The primary key of a weak entity set is created by combining the primary key of
the strong entity on which the weak entity is existence dependent and the weak
entity’s discriminator.
 We underline the discriminator attribute of a weak entity set with a dashed line.
 Payment entity has payment-no which is discriminator.
 Loan entity has loan-no as primary key.
 So primary key for payment is (loan-no, payment-no).
Superclass v/s Subclass
Super Class Sub Class
A superclass is an entity from which A subclass is an entity that is derived
another entities can be 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 account.
So an account is superclass. So saving_account and current_account
are subclass.
Account Super
Class

Saving_Account Current_Account

Sub Class
Generalization v/s Specialization

Generalization Specialization
It splits an entity to form multiple new
It extracts the common features of multiple
entities that inherit some feature of the
entities to form a new entity.
splitting entity.
Name Address Name Address

SPI Salary
Person Person

Name Name

ISA ISA
Address Address
Bottom-up approach

Student Faculty Student Faculty

SPI Salary SPI Salary


Generalization v/s Specialization
Generalization Specialization
The process of creation of group from The process of creation of sub-groups
various entities is called generalization. within an entity is called specialization.
It is Bottom-up approach. It is Top-down approach.
The process of taking the union of two or The process of taking a sub set of higher
more lower level entity sets to produce level entity set to form a lower level
a higher level entity set. entity set.
It starts from the number of entity sets It starts from a single entity set and
and creates high level entity set using creates different low level entity sets
some common features. using some different features.
Generalization & Specialization example

Name Address

PID City
Person

ISA

Salary Employee Customer Balance

ISA

Full Time Part Time

Days Worked Hour Worked


Exercise
 Give the examples of Generalization/Specialization in the following E-R diagram:
 Hospital Management System.
 College Management System.
 Bank Management System.
 Insurance Company.
Constraints on Specialization and Generalization

Constraints

Disjoint Participation

Non-disjoint Total Partial


Disjoint
(Overlapping) (Mandatory) (Optional)
Disjoint Constraint
 It describes relationship between members of the superclass and subclass and
indicates whether member of a superclass can be a member of one, or more than one
subclass.
 Types of disjoint constraints
 Disjoint Constraint
 Non-disjoint (Overlapping) Constraint
Disjoint Constraint
 It specifies that the entity of a super class can belong to only one lower-level entity set (sub class).
 Specified by ‘d’ or by writing disjoint near to the ISA triangle.

Employee
(Super class)
Cricketer
(Super class)

Disjoint
Batsman Bowler ISA
(Sub class) (Sub class)

Full-time Part-time
(Sub class) (Sub class)

All the players are associated with only one sub class either (Batsman or
Bowler).
Non-disjoint (Overlapping) Constraint
 It specifies that an entity of a super class can belong to more than one lower-level entity set (sub class).
 Specified by ‘o’ or by writing overlapping near to the ISA triangle.

Employee
(Super class)
Cricketer
(Super class)

disjoint
Non-
Batsman Bowler ISA
(Sub class) (Sub class)

Faculty Head
(Sub class) (Sub class)

One player (Paras) is associated with more than one sub class.
Constraints on Specialization and Generalization

Constraints

Disjoint Participation

Non-disjoint Total Partial


Disjoint
(Overlapping) (Mandatory) (Optional)
Participation (Completeness) Constraint
 It determines whether every member of super class must participate as a member
of subclass or not.
 Types of participation (Completeness) Constraint
 Total (Mandatory) participation
 Partial (Optional) participation
Total (Mandatory) Participation
 Total participation specifies that every entity in the superclass must be a member of
some subclass in the specialization.
 Specified by a double line in E-R diagram.
Employee
(Super class)
Cricketer
(Super class)

Batsman Bowler ISA


(Sub class) (Sub class)

Professor Head
(Sub class) (Sub class)

All the players are associated with minimum one sub class either (Batsman or
Bowler).
Partial (Optional) Participation
 Partial participation specifies that every entity in the super class does not belong to any of
the subclass of specialization.
 Specified by a single line in E-R diagram.
Employee
(Super class)
Cricketer
(Super class)

Batsman Not associated with Bowler ISA


(Sub class) any sub class (Sub class)

Professor Head
(Sub class) (Sub class)
Limitation of E-R diagram
 In E-R model we cannot express relationships between two relationships.

Relation 1 Relation Relation 2

Entity 1 Relation Entity 2


Limitation of E-R diagram

Customer
Company

Employee Works Department


Customer
Can not connect two
relationship
Borrow Borrow

Loan Loan

Process of creating an entity by combining various


components of E-R diagram is called aggregation.
 Design a database for a hospital with a set of patients who
may be in or out patient and a set of medical doctors who
treat patients. Associate with each patient a log of the
various tests and examinations conducted as medical
report. Your design should include an E-R diagram, a set of
relational schemas, and a list of constraints, including
primary-key and foreign-key constraints.
E-R diagram of Hospital Management System

MRID
PatID Name HosID Name

Medical Record Has Patient Admitted Hospital

Report Name ISA Has

Indoor Outdoor
Doctor

RoomNo
IPID
OPID
DrID Dr Name
Charge
Reduce the E-R diagram to database schema

1: Reduce Entities and Simple Attributes:


 An entity of an ER diagram is turned into a table.
PersonID Name
 Each attribute (except multi-valued attribute) turns into a column
(attribute) in the table.
 Table name can be same as entity name. Person
 Key attribute of the entity is the primary key of the table which is
usually underlined.
Address City
 It is highly recommended that every table should start with its primary
key attribute conventionally named as TablenameID.
PhoneNo

Person (PersonID, Name, Address, City)


Conversion of ER diagram into Relational Model

1) Entity set: An entity set is mapped with a relation.


The attributes of the relation include the attributes of an entity
The key attribute of an entity becomes primary key of the relation
Employee
empNo Ename Salary empNo Ename Salary

Employee

Entity Set with composite attribute:


In relational model, it doesn’t represent composite attributes as it is, just take the composition
The attribute of a relation includes the simple attributes of an entity set.
Employee
TA
empNo Ename TA MA Basic
empNo Ename Salary
MA
Basic
Employee
Reduce the E-R diagram to database schema

2: Reduce Multi-valued Attributes: PersonID PhoneNo

 Multi-value attribute is turned into a new table.


 Add the primary key column into multi-value attribute’s table. Person
 Add the primary key column of the parent entity’s table as a foreign
key within the new (multi-value attribute’s) table.
PhoneNo (PhoneID, PersonID, PhoneNo)
 Then make a 1:N relationship between the Person table and PhoneNo
table.
Person (T1)
Foreign Key

Having

PhoneNo (T2)
2) Entity set with multivalued Attributes:
if an entity contains multivalued attributes. It is represented with
two relations one with simple attributes and other with key and all
multivalued attributes.

Employee Foreign key

empNo Ename Mobile empNo Mobile


Mobile
empNo Ename 1 Bibek ID
1 1 980111
2 Sandesh

Employee 3 Rajani
2 1 9841….
4 Sanjeev
5 Simran
Reduce the E-R diagram to database schema
WifeID WName
3: Reduce 1:1 Mapping Cardinality:
 Convert both entities in to table with proper attribute.
Wife
 Place the primary key of any one table in to the another table as a
foreign key.
 Place the primary key of the Wife table WifeID in the table Persons as Having
Foreign key.
OR Person
 Place the primary key of the Person table PersonID in the table Wife as
Foreign key.
PersonID PName

Person (PersonID, PName)


Wife (WifeID, Wname, PersonID)

Wife (WifeID, Wname)


Person (PersonID, Pname, WifeID)
Reduce the E-R diagram to database schema
HouseID HName
4: Reduce 1:N Mapping Cardinality:
 Convert both entities in to table with proper attribute.
House
 Place the primary key of table having 1 mapping in to the another
table having many cardinality as a Foreign key.
 Place the primary key of the Person table PersonID in the table House Having
as Foreign key.

Person

PersonID PName

Person (PersonID, PName)


House (HouseID, Hname, PersonID)
Reduce the E-R diagram to database schema
ActNo Balance
5: Reduce N:N Mapping Cardinality:
 Convert both entities in to table with proper attribute.
Account
 Create a separate table for relationship.
 Place the primary key of both entities table into the relationship’s
table as foreign key. Has_Acct

 Place the primary key of the Customer table CID and Account table Ano
in the table Has_Acct as Foreign key. Customer

CID CName

Customer (CID, CName)


Account (ActNo, Balance)
Has_Acct (HasAcctID, CID, ActNo)
2 table, where table with many
Did Dname
empNo Ename relation will have information of
relation with foreign key of another
M 1 table
Works
Employee Department
on

2 table, where table with many


relation will have information of
1 M relation with foreign key of another
Works
Employee Department table
on

1 1 2 table, where either table can have


Employee manage Department
information of relation

M N 3 tables, all separately represented


Employee manage Department
6) Translating relationship set into a table:
A relationship set is mapped into a relation, the attributes of a
relation includes
- the key attributes of the participating relation and are declared
as foreign keys to the respective relation
- Descriptive attributes (if any)
- Set of Non descriptive attributes is the primary key of the
relation
Since
Dnam
empNo Ename Salary Did
e

Employee works Department

Employee Works Department

empNo Ename Salary empNo Did Since Did Dname


1 ram 25 k 1 1 Sep-20- 1 IT
2021
Each department is required to have atmost one employee as a manager.

empNo Ename Salary Did Dname

M 1
Employee manager Department

Employee manager Department

empNo Ename Salary empNo Did Did Dname


1 Shyam 160 k 1 1 1 IT
2 kunjan 175 k 2 2 2 Computer

Did Dname empNo


1 IT 1
2 Computer 2
Find the min no of tables that are possible when you
translate the given E-R diagram into relational model

a1 a2

b1
1 M
A R1 B b2

1 N B,R1(b1,b2,a1)
A(a1,a2)

M M
R3(b1,c1)
C
C,R2(c1,c2,a1)

c1 c2
Find the min no of tables that are possible when you
translate the given E-R diagram into relational model

B,R1,R5(b1,b2,a1,c1)
a1 a2

b1

1 M
A(a1,a2) A R1 B b2
1

R2(a1,c1) M : N R4 1:M
1

M 1
C,R3(c1,c2,d1) C D D,R4(d1,d2,b1)

c1 c2 d1 d2
Summery of Symbols used in E-R diagram

Customer Name Hold


Entity Attribute Relationship

EmpID Age PhoneNo

Primary Key Derived Multi Valued


Attribute Attribute Attribute

Payment PymtID Issue

Weak Entity Discriminating Weak Entity


Attribute Relationship
Role
Name
E R E R ISA

Total Role Specialization/


Participation Indicator Generalization
Summery of Symbols used in E-R diagram

Disjoint

E R E ISA ISA
One to One Total Disjoint
Specialization Specialization
/ /
E R E
Generalization Generalization
One to Many

E R E Overlapping

Many to One ISA ISA

Partial Overlapping
E R E Specialization Specialization
/ /
Many to Many
Generalization Generalization
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
 Default
 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.

 Default
 This constraints ensures that a column gets a default value if it is not entered.
 E.g. value of country will be ‘Nepal’ if we set country as default when this attribute is not entered.
Referential 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

DeptID Dept_Name HOD RollNo Student_Name DeptID


1 Computer Sujan 101 Ram Bhandari 1
2 BEIE Smitri 102 Laxmi yadav 2
Questions asked in TU
1. Write a note on mapping cardinality in E-R diagram.
2. Explain the difference between a weak and a strong entity set.
3. Explain the difference between generalization and specialization. OR Explain
specialization and generalization concept in E-R diagram with suitable example.
4. Write a note on constraints on specialization and generalization.
5. Explain aggregation in E-R diagram with example.
6. What do you mean by integrity constraints? Discuss various integrity constraints.
Questions asked in TU [E-R diagrams]
7. Draw E-R diagram for Bank Management System.
8. Define E-R diagram. Draw an E-R diagram for Library Management System. Assume
relevant entities and attributes for the given system.
9. Construct an E-R diagram for a car-insurance company whose customers own one or
more cars each. Each car has associated with it zero to any number of recorded
accidents.
10. Design a generalization–specialization hierarchy for a motor-vehicle sales company. The
company sells motorcycles, passenger cars, vans, and buses. Justify your placement of
attributes at each level of the hierarchy. Explain why they should not be placed at a
higher or lower level.
Questions asked in TU [E-R diagrams and Database]
11. Design a database for an airline. The database must keep track of customers and
their reservations, flights and their status, seat assignments on individual flights, and
the schedule and routing of future flights. Your design should include an E-R diagram,
a set of relational schemas, and a list of constraints, including primary-key and
foreign-key constraints.
12. Design a database for a hospital with a set of patients and a set of medical
doctors. Associate with each patient a log of the various tests and examinations
conducted. Your design should include an E-R diagram, a set of relational schemas,
and a list of constraints, including primary-key and foreign-key constraints.
13. You are given the requirement for a simple database for the national football
league(NFL). The NFL has many teams, and each team has a name, a city, a coach, a
captain and a set of players. Each players belong to only one team and each player
has a name, a position (such as left wing, mid fielder or a goal keeper) , a skill level,
and a set of injury records. A team captain is also a player who guide other player
and a game is played between two teams(referred as host team and guest team) and
has a match date( such as june 11, 2018) and score (such as 2 to 5) (2075 baisakh)
Airline

Customers
has Flight status

seat flights route flight route

ISA

National International
flights flights
NFL

has

captain
teams Guided
has players
by

ISA Record
injury
of

Host team match Guest team


Questions asked in TU [E-R diagrams and Database]
14.Aproduction company consists of a machining, fabrication and
assembly department. Employees are assigned to different
departments. Each department is managed by a manager. Each
Employee has at most one recognized skill, but a given skill may be
possessed by several employees. An employee is able to operate a
given machine-type(e.g. lathe, grinder, welding) of each department.
Some of the employees are paid overtime and some of them are paid
with daily basis. According to their designation(e.g. mechanic, welder)
are supposed to maintain at least one machine-type of their
department. Raw materials are bought from different vendors and
fetched to the machining department. Parts from machining
department are fetched to fabrication department and so on. Many
parts are assembled together to form a product. The final products
from assembly department together to form a product. The final
products are stored in the ware house. Products are labeled with
different specifications(e.g. Product_Id, product_type, MRP, etc)
Thank You

You might also like