Module 1
Module 1
Module 1
1
Contents of Module-1
Database system concepts and its architecture
Data models, schema and instances
By Dr Pawan Singh Mehra
What is Data?
3
What is Information?
By Dr Pawan Singh Mehra
Redundancy
By Dr Pawan Singh Mehra
No
No backup
File
concurrent
and Recovery
Access
System
Uncontrolled/
Inconsistency Unauthorized
access
6
Database Management System
DATABASE DBMS USER
By Dr Pawan Singh Mehra
9
Database Application Examples
Enterprise Information
Sales: customers, products, purchases
Accounting: payments, receipts, assets
By Dr Pawan Singh Mehra
Web-based services
• Online retailers: order tracking, customized recommendations
• Online advertisements
Document databases
Navigation systems: For maintaining the locations of varies places of
interest along with the exact routes of roads, train systems, buses, etc.
11
Architectures in DBMS Applications
Database applications are usually partitioned into two types
Two-tier architecture -- the application resides at the client machine,
where it invokes database system functionality at the server machine
By Dr Pawan Singh Mehra
12
Architectures in DBMS Applications
By Dr Pawan Singh Mehra
13
Source: Korth, 7th Edition
Who controls DBMS?
A person who has central control over the system is called a Database
administrator (DBA).
Functions of a DBA include:
By Dr Pawan Singh Mehra
• Schema definition
• Storage structure and access-method definition
• Schema and physical-organization modification
• Granting of authorization for data access
• Routine maintenance
• Periodically backing up the database
• Ensuring that enough free disk space is available for normal
operations, and upgrading disk space as required
• Monitoring jobs running on the database
14
Data Models
A collection of tools for describing
• Data
• Data relationships
By Dr Pawan Singh Mehra
• Data semantics
• Data constraints
Relational data model
Entity-Relationship data model (mainly for database design)
Object-based data models (Object-oriented and Object-relational)
Semi-structured data model (XML)
Other older models:
• Network data model
• Hierarchical data model
15
Relational Data Model
All the data is stored in various tables.
Example of tabular data in the relational model Columns
By Dr Pawan Singh Mehra
Rows
16
A Sample Relational Model
Columns
By Dr Pawan Singh Mehra
Rows
17
Data Abstraction
Hide the complexity of data structures to represent data in the
database from users through multiple levels of data abstraction
By Dr Pawan Singh Mehra
18
Levels of Abstraction
Physical level: describes how a record is physically stored in drive(data
structures/File types/ Way of retrieving or searching data/Indexes
etc./Locations/)
By Dr Pawan Singh Mehra
View of Data
20
Schemas and Instances
Schema- The overall design of the database
• Similar to types and variables in programming languages
Logical Schema – the overall logical structure of the database
By Dr Pawan Singh Mehra
name varchar(20),
dept_name varchar(20),
salary numeric(8,2))
DDL compiler generates a set of table templates stored in a data
dictionary
Data dictionary contains metadata (i.e., data about data)
• Database schema
• Integrity constraints
Primary key (ID uniquely identifies instructors)
• Authorization
Who can access what
23
Data Manipulation Language(DML)
Language for accessing and updating the data organized by the
appropriate data model
• DML also known as query language
By Dr Pawan Singh Mehra
25
Database Engine
A database system is partitioned into modules that deal with each of
the responsibilities of the overall system.
The functional components of a database system can be divided into
By Dr Pawan Singh Mehra
26
Storage Manager
The storage manager is responsible for storing, retrieving, and
updating data in the database
It is also responsible for
By Dr Pawan Singh Mehra
Optimization
minimizes the cost of query evaluation
Evaluation
Once the query plan is chosen, the query
is evaluated with that plan,
28
Transaction Management
A transaction is a collection of operations that performs a single
logical function in a database application
It ensures that the database remains in a consistent (correct) state
By Dr Pawan Singh Mehra
29
Database Architecture
Centralized databases
• One to a few cores, shared memory
Client-server
By Dr Pawan Singh Mehra
30
Database Users
Naïve Users(tellers, agents, web users)
Through application interfaces
Application programmers(Computer professional)
By Dr Pawan Singh Mehra
31
Entity Relationship Model
It represents the overall logical structure of a database.
It models an enterprise as a collection of entities and relationships
The ER data model employs three basic concepts:
By Dr Pawan Singh Mehra
• entity sets,
• relationship sets,
• attributes.
The ER model also has an associated diagrammatic representation,
the ER diagram, which can express the overall logical structure of a
database graphically
32
Entity and Entity Sets
An entity is an object that exists and is distinguishable from other
objects.
Example: specific person, company, event, plant
By Dr Pawan Singh Mehra
An entity set is a set of entities of the same type that share the same
properties.
Example: set of all persons, companies, trees, holidays
An entity is represented by a set of attributes; i.e., descriptive
properties possessed by all members of an entity set.
Example:
instructor = (ID, name, salary )
course= (course_id, title, credits)
A subset of the attributes form a primary key of the entity set; i.e.,
uniquely identifying each member of the set. 33
Entity and Entity Sets
By Dr Pawan Singh Mehra
34
Relationship Sets
A relationship is an association among two or more entities
Example:
By Dr Pawan Singh Mehra
Example:
(44553,22222) ϵ advisor 35
By Dr Pawan Singh Mehra
Relationship Set
36
Entity Set and Relationship Set via ER Diagram
By Dr Pawan Singh Mehra
37
Attributes of Entity Set
Attributes: A characteristic or trait of an entity type that describes the
entity
Types of attributes
By Dr Pawan Singh Mehra
Simple
Composite
Multivalued
Derived
Key attribute
38
Entity Set with Attributes
By Dr Pawan Singh Mehra
COMPOSITE
MULTI-VALUED
KEY
SIMPLE DERIVED
39
Entity Set with Attributes
By Dr Pawan Singh Mehra
40
Roles
Entity sets of a relationship need not be distinct
The labels “manager” and “worker” are called roles; they specify how
employee entities interact via the works_for relationship set.
By Dr Pawan Singh Mehra
Roles are indicated in E-R diagrams by labeling the lines that connect
diamonds to rectangles.
Role labels are optional, and are used to clarify semantics of the
relationship
41
Degree of a Relationship Set
It is the number of entity sets involved
Binary relationship involve two entity sets(i.e. Degree 2)
Most of the relationship sets in a database system are binary
By Dr Pawan Singh Mehra
42
Mapping Cardinality
It expresses the number of entities to which another entity can be
associated via a relationship set.
Most useful in describing binary relationship sets.
By Dr Pawan Singh Mehra
43
One to One Relationship
By Dr Pawan Singh Mehra
a directed line (), signify “one,” or an undirected line (—), signify “many”
44
One to Many Relationship
By Dr Pawan Singh Mehra
a directed line (), signify “one,” or an undirected line (—), signify “many”
45
Many to One Relationship
By Dr Pawan Singh Mehra
a directed line (), signify “one,” or an undirected line (—), signify “many”
46
Many to Many Relationship
By Dr Pawan Singh Mehra
a directed line (), signify “one,” or an undirected line (—), signify “many”
47
Total Participation and Partial Participation
Total participation (indicated by double line): every entity in the
entity set participates in at least one relationship in the relationship set
By Dr Pawan Singh Mehra
51
Extended ER Diagram: Specialisation & Generalisation
Specialisation
Top-down design process; we designate subgroupings within an entity set
that are distinctive from other entities in the set.
By Dr Pawan Singh Mehra
53
Extended ER Diagram: Aggregation
Consider the ternary relationship works_on, which we saw earlier
Suppose we want to record managers for tasks performed by an
employee at a branch( i.e. want to assign a manager to each
By Dr Pawan Singh Mehra
54
Extended ER Diagram: Aggregation
Suppose we want to
record managers for
tasks performed by an
By Dr Pawan Singh Mehra
employee at a branch
( i.e. want to assign a
manager to each
employee, job and
branch)
55
Extended ER Diagram: Aggregation
Relationship sets works_on and manages represent overlapping
information
Every manages relationship corresponds to a works_on relationship
By Dr Pawan Singh Mehra
56
Extended ER Diagram: Aggregation
Without introducing
redundancy, the
following diagram
By Dr Pawan Singh Mehra
represents:
An employee works on
a particular job at a
particular branch
An employee, branch,
job combination may
have an associated
manager
57
Symbols used in E-R Diagram
By Dr Pawan Singh Mehra
58
Symbols used in E-R Diagram (Cont.)
By Dr Pawan Singh Mehra
59
Symbols used in E-R Diagram (Cont.)
60
Reducing ER Diagrams to Tables
Rule 1 : Strong Entity Set with Simple attributes
Rule 2 : Strong Entity Set with Composite attributes
Rule 3 :Strong Entity Set with Multi Valued Attributes
By Dr Pawan Singh Mehra
61
Rule1: Strong Entity Set with Simple attributes
A strong entity set with only simple attributes will require only one
table in a relational model.
Attributes of the table will be the attributes of the entity set
By Dr Pawan Singh Mehra
The primary key of the table will be the key attribute of the entity
set.
62
Rule2: Strong Entity Set with Composite attributes
A strong entity set with any number of composite attributes will require
only one table in relational model.
While conversion, simple attributes of the entity will be considered for
By Dr Pawan Singh Mehra
63
Rule3:Strong Entity Set with Multi Valued Attributes
A strong entity set with any number of multi-valued attributes will
require 1+ N tables in relational model where N represents number of
multivalued attributes.
By Dr Pawan Singh Mehra
One table will contain all the simple attributes with the Primary Key
N tables will contain the Primary Key and one of the multi valued
attributes(If minimum asked then 1 table only for multivalued
attributes) Roll_No (PK) Name Address
64
Rule4:Binary relationship with cardinality ratio M:N
In many to many relationship, three tables will be required
By Dr Pawan Singh Mehra
A1(PK) A2 A1 B1 C1 B1(PK) B2
PK={A1,B1}
65
Rule5:Binary relationship with cardinality ratio 1:N
In One to many relationship two tables will be required
By Dr Pawan Singh Mehra
66
Rule6:Binary relationship with cardinality ratio N:1
In many to one relationship two tables will be required
By Dr Pawan Singh Mehra
67
Rule 7:Binary relationship with cardinality ratio 1:1
In One to One relationship two tables will be required.
By Dr Pawan Singh Mehra
68
Rule 8: Binary relationship with Weak Entity Set
The cardinality ratio between Strong and Weak Entity Set is always 1:N
B1 is the discriminator attribute
By Dr Pawan Singh Mehra
A1(PK) A2 A1 B1 B2 C1
PK={A1,B1}
69
Rule 9: Binary relationship-Total participation constraint
Rule1: Strong Entity Set with Simple attributes
By Dr Pawan Singh Mehra
70
Rule 10: N-Ary relationship
By Dr Pawan Singh Mehra
71
PK={A1,B1,D1}
Keys in DBMS
A key is an attribute or set of attributes that uniquely a tuple(a row) in
relation(table)
It is also used to establish and identify relationship between tables
By Dr Pawan Singh Mehra
Types of Keys
Super Key
Candidate Key
Primary Key
Alternate Key
Foreign Key
72
Super Key
It is a combination of all possible attributes that can uniquely identify
the tuple in a given relation
It is a superset of candidate key
By Dr Pawan Singh Mehra
Relation: Student
74
Primary Key
It is one of the candidate key chosen by the DBA to uniquely identify a
tuple
Primary Key can never be NULL
By Dr Pawan Singh Mehra
Relation: Student
75
Alternate Key
From the available set of candidate keys, One key is chosen as Primary
key, rest of the keys are called Alternate Keys
By Dr Pawan Singh Mehra
Relation: Student
76
Foreign Key
A key used to link two tables together
When Table B refers Primary Key of Table A, then the Primary Key
attribute Table A will be added into Table B as Foreign Key.
By Dr Pawan Singh Mehra