0% found this document useful (0 votes)
19 views175 pages

Unit I

The document provides an overview of database systems, including definitions of data, databases, and database management systems (DBMS). It discusses the properties, advantages, and disadvantages of DBMS, as well as the roles of different users and data models. Additionally, it highlights the importance of data integrity, security, and the challenges associated with traditional file systems.

Uploaded by

idyllic.bns1921
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)
19 views175 pages

Unit I

The document provides an overview of database systems, including definitions of data, databases, and database management systems (DBMS). It discusses the properties, advantages, and disadvantages of DBMS, as well as the roles of different users and data models. Additionally, it highlights the importance of data integrity, security, and the challenges associated with traditional file systems.

Uploaded by

idyllic.bns1921
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
You are on page 1/ 175

UNIT I

Database system
architecture

1
Syllabus
• Data Abstraction,
• Data Independence,
• Data Definition Language (DDL),
• Data Manipulation Language (DML).
• Data models:
– Entity-relationship model,
– network model,
– relational and
– object-oriented data models,
• integrity constraints,
• data manipulation 2
Introduction

3
What is data?
• A collection of facts from which conclusion
may be drawn.
• Data is often obtained as a result of recordings
or observations.
• Data is the plural form of datum.
• The temperature of the days is data.

4
Temperature of the days
• When this data is to be collected, a system or
person monitors the daily temperatures and
records it.
• Finally when it is to be converted into
meaningful information, the patterns in the
temperatures are analyzed and a conclusion
about the temperature is arrived at.
• So information obtained as a result of
analysis, communication, or investigation.
5
Properties of Data
• Data should be well organized.
• Data should be related.
• Data should be accessible in any order.
• One data should be stored minimum number
of times.

6
What is a Database?
Database is a collection of related data, that
contains information about an entity.
For example:
1. University database
2. Employee database
3. Student database
4. Airlines database

7
Properties of Database
• A database represents some aspect of the real
world, sometimes called the miniworld or the
universe of discourse (UoD).
• A database is a logically coherent collection of
data with some inherent meaning.
• A database is designed, built and populated
with data for a specific purpose.

8
What is Database Management System
(DBMS)?
• A database management system (DBMS) is a collection of
programs that enables users to create & maintain a database. It
facilitates the definition, creation and manipulation of the
database.
• Definition – it holds only structure of database, not the data. It
involves specifying the data types, structures & constraints for the
data to be stored in the database.
• Creation –it is the inputting of actual data in the database. It
involves storing the data itself on some storage medium that is
controlled by the DBMS.
• Manipulation-it includes functions such as updation, insertion,
deletion, retrieval of specific data and generating reports from the
data.
9
Typical DBMS Functionality
• Define a database : in terms of data types,
structures and constraints
• Construct or Load the Database: on a
secondary storage medium
• Manipulating the database : querying,
generating reports, insertions, deletions and
modifications to its content
• Concurrent Processing and Sharing by a set of
users and programs: yet, keeping all data valid
and consistent
10
Typical DBMS Functionality
Other features:
– Protection or Security measures to prevent
unauthorized access
– “Active” processing to take internal actions
on data
– Presentation and Visualization of data

11
Database System
• The database and the DBMS together is called the
database system.
• Database systems are designed to manage large bodies of
information.
• It involves both defining structures for storage of
information & providing mechanisms for the manipulation
of information.
• Database system must ensure the safety of the information
stored.
• Meta data- it is the data about the data. It contains the
structure of the database as well as the physical location of
the database.
12
A simplified database system
environment

13
Database System Applications
• Banking- for customer information, accounts & loans, and banking
transactions.
• Airlines-for reservations & schedule information.
• Universities-for student information, course registration and grades.
• Credit card transactions-for purchases on credit cards & generation of
monthly statements.
• Telecommunication-for keeping records of calls made, generating
monthly bills, maintaining balances, information about communication
networks.
• Finance-for storing information about holdings, sales & purchases of
financial instruments such as stocks & bonds.
• Sales-for customer, product and purchase information.
• Manufacturing-for management of supply chain & for tracking
production of items in factories.
• Human resources-for information about employees, salaries, payroll
taxes and benefits
14
Database system

• Oracle
• SQL Server
• DB2
• Sybase
• MySQL
• PostgreSQL
• Teradata
• Informix
• Ingres
• Amazon’s SimpleDB 15
Traditional File systems

16
Traditional File systems

• Before the evolution of DBMS, organizations


used to store information in file systems.
• The system stores permanent records in
various files & it need application program to
extract records , or to add or delete records .
• In traditional file processing, each user defines
and implements the files needed for a specific
application.

17
Traditional file system

• For example, one user, the grade reporting office, may keep a
file on students and their grades. Programs to print a student’s
transcript and to enter new grades into the file are
implemented.
• A second user, the accounting office, may keep track of
students’ fees and their payments.
• Although both users are interested in data about students,
each user maintains separate files—and programs to
manipulate these files—because each requires some data not
available from the other user’s files.
• This redundancy in defining and storing data results in wasted
storage space and in redundant efforts to maintain common
data up-to-date.
18
Disadvantages of File systems
1.Data Redundancy & Inconsistency
2.Difficulty in Accessing data
3.Data Isolation
4.Integrity Problems
5.Atomicity Problems
6.Concurrent access Anomalies Problems
7.Security Problems

19
Data Redundancy & Inconsistency

• Different programmers work on a single project , so various files are


created by different programmers at some interval of time.
• So various files are created in different formats & different programs
are written in different programming language.
• Same information is repeated.
• For example: name & address may appear in saving account file as
well as in salary account.
• This redundancy results in higher storage space & access cost.
• It also leads to data inconsistency which means that if we change
some record in one place the change will not be reflected in all the
places.
• For ex. a changed customer address may be reflected in saving
record but not any where else.

20
Difficulty in Accessing data
• Accessing data from a list is also a difficulty in file system.
• Suppose we want to see the records of all customers who
has a balance less than Rs10,000, we can either check the
list & find the names manually or write an application
program.
• If we write an application program & at some later time,
we need to see the records of customer who have a balance
of less than Rs 20,000, then again a new program has to be
written.
• It means that file processing system do not allow data to be
accessed in a convenient manner.

21
Data Isolation
• As the data is stored in various files, & various
files may be stored in different format, writing
application program to retrieve the data is
difficult.

22
Integrity Problems

• We need that data stored should satisfy certain


constraints as in a bank a minimum deposit should be
of 1000 Rs.
• Developers enforce these constraints by writing
appropriate programs but if later on some new
constraint has to be added then it is difficult to change
the programs to enforce them.

23
Atomicity Problems
• Any mechanical or electrical device is subject to failure, and
so is the computer system.
• In this case we have to ensure that data should be restored to a
consistent state.
• For example an amount of Rs 50 has to be transferred from
Account A to Account B.
• Let the amount has been debited from account A but have not
been credited to Account B and in the mean time, some failure
occurred.
• So, it will lead to an inconsistent state.
• So, we have to adopt a mechanism which ensures that either
full transaction should be executed or no transaction should be
executed i.e. the fund transfer should be atomic.
24
Concurrent access Problems
• Many systems allows multiple users to update
the data simultaneously.
• It can also lead the data in an inconsistent state.
• Suppose a bank account contains a balance of
Rs 500 & two customers want to withdraw
Rs100 & Rs 50 simultaneously.
• Both the transaction reads the old balance &
withdraw from that old balance which will
result in Rs 450 , Rs 400 which is incorrect.
25
Security Problems
• All the user of database should not be able to
access all the data.
• For example a payroll Personnel needs to
access only that part of data which has
information about various employees & are
not needed to access information about
customer accounts.

26
Advantages of DBMS

27
Advantages of DBMS
• Reducing Data Redundancy
• Sharing of Data
• Data Integrity
• Data Security
• Privacy
• Backup and Recovery
• Data Consistency

28
Reducing Data Redundancy

• The file based data management systems


contained multiple files that were stored in many
different locations in a system or even across
multiple systems. Because of this, there were
sometimes multiple copies of the same file which
lead to data redundancy.
• This is prevented in a database as there is a single
database and any change in it is reflected
immediately. Because of this, there is no chance of
encountering duplicate data.
29
Sharing of Data

• In a database, the users of the database can


share the data among themselves. There are
various levels of authorisation to access the
data, and consequently the data can only be
shared based on the correct authorisation
protocols being followed.
• Many remote users can also access the
database simultaneously and share the data
between themselves.
30
Data Integrity

• Data integrity means that the data is accurate and


consistent in the database.
• Data Integrity is very important as there are multiple
databases in a DBMS. All of these databases contain
data that is visible to multiple users.
• So it is necessary to ensure that the data is correct
and consistent in all the databases and for all the
users.

31
Data Security
• Data Security is vital concept in a database.
Only authorized users should be allowed to
access the database and their identity should
be authenticated using a username and
password.
• Unauthorized users should not be allowed to
access the database under any circumstances
as it violates the integrity constraints.

32
Privacy
• The privacy rule in a database means only the
authorized users can access a database
according to its privacy constraints.
• There are levels of database access and a user
can only view the data he is allowed to.
• For example - In social networking sites,
access constraints are different for different
accounts a user may want to access.

33
Backup and Recovery

• Database Management System automatically


takes care of backup and recovery.
• The users don't need to backup data
periodically because this is taken care of by
the DBMS.
• Moreover, it also restores the database after a
crash or system failure to its previous
condition.

34
Data Consistency

• Data consistency is ensured in a database


because there is no data redundancy.
• All data appears consistently across the
database and the data is same for all the users
viewing the database.
• Moreover, any changes made to the database
are immediately reflected to all the users and
there is no data inconsistency.

35
Disadvantages of DBMS
• Cost of Hardware & Software
• Cost of Data Conversion
• Cost of Staff Training
• Appointing Technical Staff
• Database Damage

36
Database users

37
Users may be divided into

• Those who actually use and control the content


(called “Actors on the Scene”)
• Those who enable the database to be
developed and the DBMS software to be
designed and implemented (called “Workers
Behind the Scene”).

38
Actors on the scene

– Database administrators
– Database Designers
– End-users

39
Database administrators (DBA)

• Database administrators is the controller of


the overall operations of the database.
• But he is not responsible for creating the
database or the structure of the database.
• Database administrators is the most powerful
actor on the scene.

40
Functions of DBA

• Authorizing access to the database


• Coordinating & monitoring the database
• For acquiring hardware & software resources
as needed by the user
• Concurrency control checking
• Security of the database
• Making backups & recovery
• Modification of the database structure & its
relation to the physical database
41
Database Designers (DBD)

• Database Designers is the person who designs


the database structure for the first time pre-
requisites i.e. to collect data from which
source is decided by DBD.

42
Functions of DBD
• The creation of original description of the
database structure
• Database designers interact with different
group of users & integrate their views to make
the best structure.

43
End-users

They use the data for queries, reports and some


of them actually update the database content.
Types of end-users
• Casual
• Naive or Parametric
• Sophisticated
• Specialized or Stand-alone

44
• Casual: they can only browse through the
database; they cannot create, update or make
any changes in the database. They
occasionally access the database.
• Naive or Parametric: they use the readymade
software which deals with the database. They
can only update the database. Examples are
bank-tellers or reservation clerks who do this
activity for an entire shift of operations.

45
• Sophisticated: these include business analysts,
scientists, engineers, others thoroughly
familiarize themselves with the facilities of the
DBMS so as to implement their applications to
meet their complex requirements.
• Stand-alone: mostly maintain personal
databases using ready-to-use packaged
applications. An example is a tax program user
that creates his or her own internal database.

46
Workers behind the scene

• DBMS system implementers: they are the creators of the


DBMS.

• Tools Developers: tools are the facilities provided to help the


DBMS or the user. They are packages for database design,
performance monitoring, graphical interfaces, and simulation
package. Tool developers, develop the tools for DBMS.

• Operators & maintenance personnel: these are the


workers/persons required for maintaining the hardware or
software of the DBMS.

47
Data models

48
DATA MODEL

• A model defines the manner in which various files of a database


are linked together.

• A data model can be thought of as a diagram or flowchart that


illustrates the relationships between data.

• A data model is a collection of concepts that can be used to


describe the structure of a database.

• By structure of a database we mean the


– Data types,
– Relationships,
– Constraints that should hold on the data. 49
Categories of data models
These are the category according to the type of
concepts they use to describe the database structure.
• Conceptual (high-level, semantic, entity-based,
object-based) data models
• Physical (low-level, internal) data models
• Implementation (representational, record based) data
models

50
Conceptual data models
• Conceptual data models provide concepts that are close to
the way many users perceive data.
• Before implementation, a rough model of database is
created.
• This model is never implemented but is used for designing
purpose.
• This model use concepts such as entities , attributes and
relationships.

Example: E-R Model

51
E-R model
• Stands for entity-relationship model.
Terms used in E-R model:
Attribute
Entity

52
EXAMPLE
Qu ickTime™ an d a
d ecomp ressor
are n eed ed to see this p icture.
Qu ickTime™ an d a
d ecomp ressor
are n eed ed to see this p icture.
Qu ickTim e™ an d a
d ecomp r essor Quic kTime™ and a
ar e n eed ed t o see t h is p ict u r e. dec ompres s or
are needed to s ee this pic ture.

Qu ickTime™ an d a
d ecomp ressor
are n eed ed to see this p icture.

Qu ickTime™ an d a
d ecomp ressor
are n eed ed to see this p icture.

53
Physical data models
• It provides concepts that describe the details of
how data is stored in the computer by
representing information such as record
formats(fixed/variable length), record orderings,
and access paths(key indexing).
• An access path is a structure that makes the
search for particular database records efficient.
• Concepts provided by physical data models are
generally meant for computer specialists, not for
typical end users.
54
Implementation data models
• Provide concepts that fall between the above
two.
• It also provides concepts that may be
understood by end users but that are not too far
away from the way data is organized within
the computer.
• Example: relational model, network model,
hierarchical model, object oriented model

55
Hierarchical Model
 Hierarchical Model was the first DBMS model. This
model organizes the data in the hierarchical tree
structure.
 The hierarchy starts from the root which has root data
and then it expands in the form of a tree adding child
node to the parent node.
 This model easily represents some of the real-world
relationships like food recipes, sitemap of a website etc.
 Example: We can represent the relationship between
the shoes present on a shopping website in the
following way:
56
Example

57
Features of a Hierarchical Model

• One-to-many relationship: The data here is organised in a tree-like


structure where the one-to-many relationship is between the datatypes.
Also, there can be only one path from parent to any node. Example: In the
above example, if we want to go to the node sneakers we only have one
path to reach there i.e through men's shoes node.
• Parent-Child Relationship: Each child node has a parent node but a parent
node can have more than one child node. Multiple parents are not
allowed.
• Deletion Problem: If a parent node is deleted then the child node is
automatically deleted.
• Pointers: Pointers are used to link the parent node with the child node and
are used to navigate between the stored data. Example: In the above
example the 'shoes' node points to the two other nodes 'women shoes'
node and 'men's shoes' node.

58
Advantages and Disadvantages of Hierarchical Model

Advantages of Hierarchical Model


• It is very simple and fast to traverse through a tree-like structure.
• Any change in the parent node is automatically reflected in the
child node so, the integrity of data is maintained.
Disadvantages of Hierarchical Model
• Complex relationships are not supported.
• As it does not support more than one parent of the child node so if
we have some complex relationship where a child node needs to
have two parent node then that can't be represented using this
model.
• If a parent node is deleted then the child node is automatically
deleted.

59
Network Model
• This model is an extension of the hierarchical model.
• It was the most popular model before the relational
model.
• This model is the same as the hierarchical model, the
only difference is that a record can have more than
one parent.
• It replaces the hierarchical tree with a graph.
• Example: In the example below we can see that node
student has two parents i.e. CSE Department and
Library.
• This was earlier not possible in the hierarchical model.

60
Example

61
Features of a Network Model

• Ability to Merge more Relationships: In this model, as there


are more relationships so data is more related. This model has
the ability to manage one-to-one relationships as well as
many-to-many relationships.
• Many paths: As there are more relationships so there can be
more than one path to the same record. This makes data
access fast and simple.
• Circular Linked List: The operations on the network model are
done with the help of the circular linked list. The current
position is maintained with the help of a program and this
position navigates through the records according to the
relationship.
62
Advantages and Disadvantages of Network Model

Advantages of Network Model


• The data can be accessed faster as compared to the hierarchical
model. This is because the data is more related in the network model
and there can be more than one path to reach a particular node. So
the data can be accessed in many ways.
• As there is a parent-child relationship so data integrity is present. Any
change in parent record is reflected in the child record.

Disadvantages of Network Model


• As more and more relationships need to be handled the system might
get complex. So, a user must be having detailed knowledge of the
model to work with the model.
• Any change like updation, deletion, insertion is very complex.
63
Relational Model
• Relational Model is the most widely used model.
• In this model, the data is maintained in the form of
a two-dimensional table.
• All the information is stored in the form of row
and columns.
• The basic structure of a relational model is tables.
So, the tables are also called relations in the
relational model.
• Example: In this example, we have an Employee
table.
64
Relational Model
Example of tabular data in the relational model:
name ssn street city account-number
Johnson 192-83-7465 Alma Palo Alto A-101
Smith 019-28-3746 North Rye A-215
Johnson 192-83-7465 Alma Palo Alto A-201
Jones 321-12-3123 Main Harrison A-217
Smith 019-28-3746 North Rye A-201

account-number balance
A-101 500
A-201 900
A-215 700
A-217 750

65
Features of Relational Model

• Tuples: Each row in the table is called tuple. A row


contains all the information about any instance of
the object. In the above example, each row has all
the information about any specific individual like
the first row has information about John.
• Attribute or field: Attributes are the property which
defines the table or relation. The values of the
attribute should be from the same domain. In the
above example, we have different attributes of the
employee like Salary, Mobile_no, etc.
66
Advantages and disadvantage of Relational Model

Advantages of Relational Model


• Simple: This model is more simple as compared to the network and hierarchical model.
• Scalable: This model can be easily scaled as we can add as many rows and columns we
want.
• Structural Independence: We can make changes in database structure without changing
the way to access the data. When we can make changes to the database structure
without affecting the capability to DBMS to access the data we can say that structural
independence has been achieved.

Disadvantages of Relational Model


• Hardware Overheads: For hiding the complexities and making things easier for the user
this model requires more powerful hardware computers and data storage devices.
• Bad Design: As the relational model is very easy to design and use. So the users don't
need to know how the data is stored in order to access it. This ease of design can lead to
the development of a poor database which would slow down if the database grows.

67
Object oriented data model

68
Example of Object oriented data model

There are two objects in the above example −


 Employee
 Department
Each object data and relationships are contained in a single unit. The attributes
are Name, job_title. Methods are used to perform the operation with the help of
attributes.
The two objects are connected through a common attribute department_id and
communication between these two will be done with the help of id.

69
Advantages

• The advantages of the object-oriented model


are as follows −
i. Semantic content is added.
ii. Support for complex objects.
iii. Inheritance promotes data integrity.
iv. Visual representation includes semantic
content.

70
Disadvantages

The disadvantages of the object-oriented model


are as follows:
i. It is a complex navigational system.
ii. Slow development of standards.
iii. High system overheads.
iv. Slow transactions.

71
Object relational data model

72
Schemas And Instances

73
Schemas And Instances

• The description of a database is called the


database schema, which is specified during
database design and is not expected to change
frequently.

• The collection of information stored in the


database at a particular moment is called an
instance of the database. It changes very
frequently than the schema.
74
student name student number class major
smith 17 1 cosc
brown 8 2 cosc

course courseName coursenumber Cradit hours depertment


intro to com duts s cie nce cosc1310 4 cosc
data s tr ucture s cosc3320 4 cosc
dis math2410 3 math
database cosc3380 3 cosc

re re quisite
pre re quisite course numbe r
numbe r
cosc3380 cosc3320
cosc3330 math2410
cosc3320 cosc1310

section sectionldentifier coursenumber semester year instructor


85 math2410 fall 86 king
92 cosc1310 fall 86 anderson
102 cosc3320 spring 87 kuuth
112 math2410 fall 87 chang
119 cosc1310 fall 87 anderson
135 cosc3380 fall 87 stone

grade_report student number sectionldentifier grade


17 112 B
17 119 C
8 85 A
8 92 A
8 102 B
8 135 A
Data abstraction

77
Data abstraction

• Method of hiding the actual (complex) details from


users is called as data abstraction.
• For the system to be usable, it must retrieve data
efficiently. The need for efficiency has led
designers to use complex data structures to
represent data in the database.
• Since many database-systems users are not
computer trained, developers hide the complexity
from users through several levels of abstraction, to
simplify users’ interactions with the system.

78
Levels of data abstraction

79
Physical level

• It is the lowest level of abstraction.


• This level of abstraction is concerned with the physical
storage of the information.
• Also known as internal level, it provides the internal
view of the actual physical storage of data.
• Although it is a low- level representation of the entire
database, it tell us what data is stored in the database
and how.

80
Logical level

• It is the next level of abstraction.


• It is a representation of the entire information
content of the database, in a form that is
somewhat abstract in comparison with the way
in which the data is physically stored.

81
View level
• This level contains the actual data which is shown
to the users.
• This is the highest level of abstraction & the user
of this level need not know the actual details of
data storage.

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

83
3-level DBMS Architecture

84
ANSI-SPARC 3-level DBMS Architecture

85
Three-schema architecture
• Where ANSI-SPARC stands for American National
Standards Institute, Standards Planning And
Requirements Committee.
• The three-schema architecture is a convenient tool for
the user to visualize the schema levels in a database
system.
• In this architecture, schemas can be defined at the
following three levels:
– Internal schema/Physical schema
– Conceptual schema
– External schema
86
• The internal level has an internal schema, which describes
the physical storage structure of the database.

• The conceptual level has a conceptual schema, which


describes the structure of the whole database for a community
of users. The conceptual schema hides the details of physical
storage structures and concentrates on describing entities, data
types, relationships, user operations, and constraints.

• The external or view level includes a number of external


schemas or user views.

• The processes of transforming requests and results between


levels are called mappings.
87
Example: university database
Physical schema:
• Relations stored as unordered files.
• Index on first column of students

Conceptual schema:
• Student (sid: string, name: string, age: number, percent: real)
• Courses (cid: string, cname: string, credits: number)
• Enrolled (enrollment: integer,sid: string, cid: string, grade:
string)

External schema:
• Course_info(cid: string, enrollment: integer)

88
DATA INDEPENDENCE

89
DATA INDEPENDENCE

• The changes can be made in one level without


affecting the other levels that is called data
independence.

• Data independence is the capacity to change


the schema at one level of a database system
without having to change the schema at the
next higher level.

90
Types of data independence
• Physical data independence is the capacity to
change the internal schema without having to
change the conceptual (or external) schemas.

• Logical data independence is the capacity to


change the conceptual schema without having
to change external schemas or application
programs.

91
Entity- Relationship Model

92
Entity- Relationship Model
• The E-R model is the most commonly used
conceptual model.
• In this model, the real world consists of a
collection of basic objects called entities and the
relationships among these objects.
• The end product of the modeling process is an
entity-relationship diagram (ERD) or ER diagram.
• But it is not implemented but design for
creating the database.

93
The E-R data model employs three basic notions:

• Entity
• Attributes
• Relationship

94
Entity
• It is an object with a physical existence.
• For example, each person in an enterprise ,
car, house, a company, student.

95
Entity Type & Entity Sets
• Entity Type –
– collection of entities that have the same attributes.
Ex: STUDENT

STUDENT

• Entity Set – Name Age Rollno


– The collection of all entities of a particular entity type.
Ex: Set of all rows
10 rows of STUDENT

96
Graphical representation of entity sets

97
Attributes
• Attributes are the particular properties that
describe an entity.
Ex: A STUDENT entity may be described by
student’s name, student’s roll_number.

98
Graphical representation of attributes

99
Types of Attributes

• Simple (Atomic) and Composite Attributes


• Single Valued & Multi-valued Attributes
• Stored and Derived Attributes
• Null Valued Attributes
• Complex Attributes

100
Simple (Atomic) and Composite Attributes

• Simple attributes are not divisible into parts.


For example, EmployeeNumber and Age.
• Composite attributes can be divided into
smaller subparts. These subparts represent
basic attributes with independent meanings of
their own. For example, take Name and
address attributes.

101
Address

Street Address city state Pin

number apartment no.


street

102
Single Valued & Multi-valued Attributes

• Single-valued attributes have a single value for


particular entity. Example: Roll_no, Age.
• Multi-valued attributes may have more than
one value for a single entity. Example:
Phone_no

103
Stored and Derived Attributes

• Derived attribute is not stored in the database


but it is derived from some attributes.
• Example: If DOB is stored in the database
then we can calculate age of a student by
subtracting DOB from current date.
• Hence, in this case DOB is the stored attribute
and age is considered as derived.

104
Null Valued Attributes

• Null value is a value which is not inserted but


it does not hold zero value.
• The attributes which can have a null value
called null valued attributes.
• Example: Mobile_no attributes of a person
may not be having mobile phones.

105
Complex Attributes

• Complex attribute is a combination of


composite and multi-valued attributes.
Complex attributes are represented by { } and
composite attributes are represented by ( ).
• Example: Address_phone attribute will hold
both the address and phone_no of any
person.
• Example: {(2-A, St-5, Sec-4, Bhilai), 2398124}

106
Key attribute in an entity type
• Key attributes will be having a unique value for
each entity of that attribute.
• It identifies every entity in the entity set.
• Key attribute will never be a null valued attribute.
• Any composite attribute can also be a key
attribute.
• There could be more than one key attributes for
an entity type.
Example: roll_no, enrollment _no

107
Domain of value set of an attribute
• Domain of an attribute is the allowed set of
values of that attribute.
Example: if attribute is ‘grade’, then its allowed
values are A,B,C,F.
• Grade ={A, B,C,F}

108
TYPES OF ENTITY TYPES
Strong entity type – Entity types that have at least one
key attribute.

Weak entity type – Entity type that does not have any
key attribute.
An entity in a weak entity type is identified by a
relationship with a strong entity type and that
relationship is called Identifying Relationship and that
strong entity type is called the owner of the weak entity
type.

109
TYPES OF ENTITY TYPES
Student
Roll No. Name Age
1 Rakesh 20
2 Nikhil 21
3 Nikhil 21

Secured
Marks
Name M1 M2 M3
Nikhil 50 45 40
Nikhil 80 75 82

Identifying Relationship

110
Relationship
• Relates two or more distinct entities with a specific meaning.
– For example, EMPLOYEE John works on the ProductX
PROJECT
or
– EMPLOYEE Franklin manages the Research
DEPARTMENT.

Terms used:
Relationship type,
Relationship set,
Relationship instances.
111
Relationship type: secured
Relationship set: {R1, R2, R3, R4}
Relationship instances: R1
112
Graphical Representation of Relationship Sets

113
NOTATIONS USED IN E-R DIAGRAM
Entity Type

Weak Entity Type

Attribute

Key Attribute

114
NOTATIONS USED IN E-R DIAGRAM

Composite Attribute

Derived Attribute

Multivalued Attribute

115
NOTATIONS USED IN E-R DIAGRAM

Relationship Type

Identifying Relationship

116
Example of E-R Diagrams

 Rectangles represent entity types.


 Diamonds represent relationship types.
 Lines link attributes to entity types and entity types to relationship types.
 Ellipses represent attributes
 Underline indicates primary key attributes (will study later)

117
E-R Diagram With Composite, Multivalued, and Derived
Attributes

118
Relationship Types with Attributes

we have the access_date attribute attached to the relationship set


depositor to specify the most recent date on which a customer
accessed that account.

119
Constraints
Relationship types usually have certain
constraints. Two main types of relationship
constraints:

• Mapping cardinalities
• Participation constraints

120
Mapping cardinalities, or cardinality ratios

• Specifies the number of relationship instances


that an entity can participate in.

121
Mapping Cardinalities

• One-to-one (1:1)
• One-to-many (1: N)
• Many-to-one (N: 1)
• Many-to-many (M: N)

122
Cardinality ratio
• We express cardinality ratio by drawing
directed line (→), signifying “one,” or an
undirected line (—), signifying “many,”

123
One-To-One Relationship

124
One-To-Many Relationship

• In the one-to-many relationship a customer is associated with


several loans via borrower

125
Many-To-One Relationships
• In a many-to-one relationship a loan is associated with several
customers via borrower.

126
Many-To-Many Relationship

• A customer is associated with several (possibly 0) loans via


borrower
• A loan is associated with several (possibly 0) customers via
borrower

127
Find out the Cardinality ratio
• Prime minister-country
• classroom –students
• students –classroom
• customer -loan

128
Participation constraints
 Total participation : every entity in the entity type participates in at least
one relationship in the relationship type (displayed by double line)
 E.g. participation of loan in borrower is total
 every loan must have a customer associated to it via borrower
 Partial participation: some entities may not participate in any relationship
in the relationship type (displayed by a single line).
 Example: participation of customer in borrower is partial
 some customers may not participate in any loan

129
KEYS

• Key is used to identify every entity in the


entity set.

130
Types of keys
• Candidate Key
• Alternate & Primary key
• Superkey

131
Candidate Key
• It is the minimal set of attributes that uniquely identifies any
entity in entity set.
• There can be more than one candidate keys in entity set.
• More than one attribute can together form a single candidate key.
• Suppose that a combination of customer-name and customer-street
is sufficient to distinguish among members of the customer entity
set.
• Then, both {customer-id} and {customer-name, customer-street}
are candidate keys.
• Although the attributes customer-id and customer-name together
can distinguish customer entities, their combination does not form
a candidate key, since the attribute customer-id alone is a
candidate key.

132
Alternate & Primary key
• Alternate & Primary key is related with
candidate key.
• In entity set, primary key is a candidate key
but only one key is the primary key & the left
candidate keys are called alternate key.
• AK=CK-PK

133
Superkey
• A superkey is the superset of any candidate key.
• For example, the customer-id attribute of the entity set
customer is sufficient to distinguish one customer entity
from another.
• Thus, customer-id is a superkey.
• Similarly, the combination of customer-name and
customer-id is a superkey for the entity set customer.
• The customer-name attribute of customer is not a
superkey, because several people might have the same
name.
• Example: {customer-id}, {customer-name, customer-id}
134
Weak Entity Types
• An entity type that does not have a primary key is
referred to as a weak entity type.

135
Weak Entity types (Cont.)
• We depict a weak entity type by double rectangles.
• We underline the partial key of a weak entity type with a
dashed line.
• payment_number – partial key of the payment entity type
• Primary key for payment – (loan_number, payment_number)

136
Give me answer?
• Can we convert weak entity type into strong
entity type?

137
Steps in ER Modeling

• Identify the Entities


• Find relationships
• Identify the key attributes for every Entity
• Identify other relevant attributes
• Draw complete E-R diagram with all attributes
including Primary Key

138
PROBLEMS ON E-R DIAGRAM

Question 1: An employee works in one


department. The department contains phone,
the employee also has phone. Assume that an
employee works in maximum 2 departments
or minimum one department. Each
department must have maximum 3 phones or
minimum zero phone. Design an E-R diagram
for the above.

139
140
Question 2
• Design an E-R diagram for keeping track of the
exploits of your favorite sports team. You
should store the matches played, the scores in
each match, the players in each match and
individual player statistics for each match.
Summary statistics should be modeled as
derived attributes.

141
Solution

142
Question 3
• Construct an E-R diagram 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.

143
Solution

144
Question 4
Construct an E-R diagram for Bank.

145
146
Integrity constraints

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

148
Types of Integrity Constraint

149
Domain constraints

• Domain constraints can be defined as the


definition of a valid set of values for an
attribute.
• The data type of domain includes string,
character, integer, time, date, currency, etc.
The value of the attribute must be available in
the corresponding domain.

150
Example:

151
Entity integrity constraints

• The entity integrity constraint states that


primary key value can't be null.
• This is because the primary key value is used
to identify individual rows in relation and if
the primary key has a null value, then we can't
identify those rows.
• A table can contain a null value other than the
primary key field.

152
Example:

153
Referential Integrity Constraints

• A referential integrity constraint is specified


between two tables.
• In the Referential integrity constraints, if a
foreign key in Table 1 refers to the Primary Key
of Table 2, then every value of the Foreign Key
in Table 1 must be null or be available in Table
2.

154
Referential Integrity
• Referential integrity is concerned with foreign keys.
Primary key and foreign key relates two tables.
• Referential integrity is a property, when satisfied, requires
every value of one attribute of a relation to exist as a value
of another attribute in a different relation.
• Less formally: For referential integrity to hold, any field in
a table that is declared a foreign key can contain only values
from a parent table's primary key.

155
Referential Integrity Constraint
The value in the foreign key column FK of the referencing relation
R1 can be either:
(1) a value of an existing primary key value of the corresponding
primary key PK in the referenced relation R2,, or..
(2) a null.

156
Example

157
Key constraints
• Keys are the entity set that is used to identify
an entity within its entity set uniquely.
• An entity set can have multiple keys, but out
of which one key will be the primary key. A
primary key can contain a unique and null
value in the relational table.

158
Example

159
Key Constraints
• Super key
• Candidate key
• Primary key
• Alternate key
• Foreign Key

160
Super key
• Super key as a set of those keys that identify a row or a tuple
uniquely. The word super denotes the superiority of a key.
• Thus, a super key is the superset of a key known as
a Candidate key. It means a candidate key is obtained from a
super key only.
• The role of the super key is simply to identify the tuples of the
specified table in the database. It is the superset where the
candidate key is a part of the super key only.
• So, all those attributes in a table that is capable of identifying
the other attributes of the table in a unique manner are all
super keys.

161
Example
• Let's consider an EMPLOYEE_DETAIL table example where we have the following attribute:
• Employee(Emp_SSN,Emp_Id,Emp_name,Emp_email)

162
Candidate key

• It is the minimal set of attributes that uniquely


identifies any tuple in a relation.
• There can be more than one candidate keys in
a relation.
• More than one attribute can together form a
single candidate key.

163
Continued…
• It is possible that several distinct sets of attributes could serve as
a candidate key.
• Suppose that a combination of customer-name and customer-
street is sufficient to distinguish among members of the customer
entity set.
• Then, both {customer-id} and {customer-name, customer-street}
are candidate keys.
• Although the attributes customer-id and customer-name together
can distinguish customer entities, their combination does not
form a candidate key, since the attribute customer-id alone is a
candidate key.

• Example: {customer-id} and {customer-name, customer-street}


164
Key Constraints

165
Alternate & Primary key

• Alternate & Primary key is related with


candidate key.
• In a relation, primary key is a candidate key
but only one key is the primary key & the left
candidate keys are called alternate key.
• AK=CK-PK

166
Foreign Key
• Foreign keys are the column of the table used to point to
the primary key of another table.
• Every employee works in a specific department in a
company, and employee and department are two different
entities. So we can't store the department's information in
the employee table. That's why we link these two tables
through the primary key of one table.
• We add the primary key of the DEPARTMENT table,
Department_Id, as a new attribute in the EMPLOYEE table.
• In the EMPLOYEE table, Department_Id is the foreign key,
and both the tables are related.
167
Example

168
DDL and DML commands

169
Structured Query Language(SQL)
• Structured Query Language(SQL) as we all know is the database
language by the use of which we can perform certain operations
on the existing database and also we can use this language to
create a database.
• SQL uses certain commands like Create, Drop, Insert, etc. to
carry out the required tasks.
• These SQL commands are mainly categorized into four
categories as:
• DDL – Data Definition Language
• DML – Data Manipulation Language
• DCL – Data Control Language
• TCL – Transaction Control Language
170
DDL (Data Definition Language)

• DDL or Data Definition Language actually consists of the


SQL commands that can be used to define the database
schema.
• It simply deals with descriptions of the database schema
and is used to create and modify the structure of
database objects in the database.
• DDL is a set of SQL commands used to create, modify,
and delete database structures but not data.
• These commands are normally not used by a general
user, who should be accessing the database via an
application.
171
List of DDL commands

• CREATE: This command is used to create the database or its


objects (like table, index, function, views, store procedure, and
triggers).
• DROP: This command is used to delete objects from the
database.
• ALTER: This is used to alter the structure of the database.
• TRUNCATE: This is used to remove all records from a table,
including all spaces allocated for the records are removed.
• COMMENT: This is used to add comments to the data
dictionary.
• RENAME: This is used to rename an object existing in the
database.
172
DML(Data Manipulation Language)

• The SQL commands that deals with the manipulation of


data present in the database belong to DML or Data
Manipulation Language and this includes most of the SQL
statements. It is the component of the SQL statement that
controls access to data and to the database. Basically, DCL
statements are grouped with DML statements.
• List of DML commands:
• INSERT : It is used to insert data into a table.
• UPDATE: It is used to update existing data within a table.
• DELETE : It is used to delete records from a database
table.
173
DCL (Data Control Language)

• DCL includes commands such as GRANT and


REVOKE which mainly deal with the rights,
permissions, and other controls of the database
system.
List of DCL commands:
• GRANT: This command gives users access
privileges to the database.
• REVOKE: This command withdraws the user’s
access privileges given by using the GRANT
command.
174
TCL
• TCL commands deal with the
transaction within the database.
List of TCL commands:

• COMMIT: Commits a Transaction.


• ROLLBACK: Rollbacks a transaction in case of
any error occurs.
• SAVEPOINT: Sets a savepoint within a
transaction.
175

You might also like