Professional Documents
Culture Documents
Systems
1
Course Objectives
2
Session Plan (1of 3)
Day1
–Data Processing
–Basic DBMS concepts
–ER modeling
Day2
–ER modeling continued
–Extended ER features
–Logical database design
–Functional dependencies
–Normalization
–Denormalization
Day3
–DDL
–DML
–Aggregate functions
3
Session Plan (2 of 3)
Day 4
– Grouped results
– Sub queries
– Relational algebra
– Use of EXISTS and NOT EXISTS
Day 5
– Views
– Concept of an index
– Embedded SQL
Day 6
– Transaction processing concepts
– OLTP
– Database integrity
– Security
– Concurrency
4
Session Plan (3 of 3)
Day 7
– Concurrency continued
– Database Recovery
– Log file
– Deferred Database update
– Immediate Database update
ER/CORP/CRS/DB07/003
Copyright © 2004, 5
Infosys Technologies Ltd Version No: 2.0
5
References
ER/CORP/CRS/DB07/003
Copyright © 2004, 6
Infosys Technologies Ltd Version No: 2.0
6
RDBMS-Day1
Data Processing
Basic DBMS concepts
Basic RDBMS concepts
Conceptual Database Design
ER Modeling Notations
7
Data Processing
Data collection
Recording
Sorting
Classifying
Calculating
Summarizing
Communicating
ER/CORP/CRS/DB07/003
Copyright © 2004, 8
Infosys Technologies Ltd Version No: 2.0
8
Data Processing modes
Batch processing:
Transactions are collected in a group & processed together.
Real-time processing:
It is a parallel time relationship with on-going activity & the information
produced is useful in controlling the current/dynamic activity.
ER/CORP/CRS/DB07/003
Copyright © 2004, 9
Infosys Technologies Ltd Version No: 2.0
9
Traditional Method of Storage
Application
Programs
File System
Files
A B C D
ER/CORP/CRS/DB07/003
Copyright © 2004, 10
Infosys Technologies Ltd Version No: 2.0
•In the traditional approach, we used to store information in flat files which are maintained by the file
system under the operating system’s control.
•Application programs go through the file system to access these flat files
10
Ways of storing data in files
ER/CORP/CRS/DB07/003
Copyright © 2004, 11
Infosys Technologies Ltd Version No: 2.0
•Records consist of various fields which are delimited by a space , comma , tab etc.
•There used to be special characters to mark end of records and end of files.
11
Problems:Traditional approach
DATA
DEPENDENCY
MULTIPLE
LOSS OF FILES
FLEXIBILITY
UPDATE
REDUNDANCY PROBLEM
INCONSISTENCY
ER/CORP/CRS/DB07/003
Copyright © 2004, 12
Infosys Technologies Ltd Version No: 2.0
•Data spread across multiple files where dependent on each other . This led to loss of flexibility.
Since data was spread across multiple files and there was no formal way of maintaining relationships
between these files, the same information was repeated in multiple files. This led to redundancy.
•When a particular data had to be updated , say for example, an employee’s information to be
deleted, it has to be done in all the files where the employee data occurs. If the deletion is missed out
on even one of the files, it would leave the data inconsistent.
12
The Database Technology
Database
ER/CORP/CRS/DB07/003
Copyright © 2004, 13
Infosys Technologies Ltd Version No: 2.0
•Application programs request the DBMS to retrieve, modify, insert or delete data for them
13
Where does the RDBMS fit in?
ER/CORP/CRS/DB07/003
Copyright © 2004, 14
Infosys Technologies Ltd Version No: 2.0
• Now, the DBMS acts as a layer of abstraction on top of the File system.
• You might have observed that, for interacting with the file system, we were using high level
language functions for example, the ‘c’ file handling functions. For interacting with the DBMS we
would be using a Query language called SQL
14
Three-layer Architecture
DBMS interface
Conceptual layer
DBMS interface
Internal layer
ER/CORP/CRS/DB07/003
Copyright © 2004, 15
Infosys Technologies Ltd Version No: 2.0
•Data management
•Data definition
•Transaction support
•Concurrency control
•Recovery
•Security & integrity
•Utilities- facilities like data import & export, user management, backup, performance
analysis, logging & audit, physical storage control
15
Advantages of a DBMS
Data independence
Reduction in data redundancy
Better security
Better flexibility
Effective data sharing
ER/CORP/CRS/DB07/003
Copyright © 2004, 16
Infosys Technologies Ltd Version No: 2.0
1. Users and application programs need not know exactly where or how the data is stored in order
to access it
2. Proper database design can reduce or eliminate data redundancy and confusion
3.Support for unforeseen (ad hoc) information requests are better supported - better flexibility
4. Data can be more effectively shared between users and/or application programs
16
Users of a DBMS
Database designers
Application Programmers
End users
ER/CORP/CRS/DB07/003
Copyright © 2004, 17
Infosys Technologies Ltd Version No: 2.0
•DBA is a key person and takes care of most administrative tasks as mentioned in the slide
•Application programmers, make use of the various database elements and write programs to retrieve data from
them
17
Database Technologies
Hierarchical Model
Network Model
Relational Model
Object-Oriented
ER/CORP/CRS/DB07/003
Copyright © 2004, 18
Infosys Technologies Ltd Version No: 2.0
Commercial Packages
18
Relational Model Basics
Data is viewed as existing in two dimensional tables known as relations
ER/CORP/CRS/DB07/003
Copyright © 2004, 19
Infosys Technologies Ltd Version No: 2.0
•Though logically data is viewed as existing in the form of two dimensional tables, actually, the data is
stored under the file system only.
•The RDBMS provides an abstraction on top of the file system and gives an illusion that data resides
in the form of tables.
19
A sample relation
Attributes
Emp table
E# EmpName Age Salary
t
u 1049 Shyam 25 19,000
p
l
e 1067 Raj 22 14,000
s
ER/CORP/CRS/DB07/003
Copyright © 2004, 20
Infosys Technologies Ltd Version No: 2.0
20
Keys
Super key
Candidate key
Primary key
Foreign key
ER/CORP/CRS/DB07/003
Copyright © 2004, 21
Infosys Technologies Ltd Version No: 2.0
Superkey
An attribute, or group of attributes, that is sufficient to distinguish every tuple in the relation from every other one.
Each super key is called a candidate key
A candidate key is all those set of attributes which can uniquely identify a row. However, any subset of these set of attributes would not
identify a row uniquely
For example, in a shipment table, “S# , P# ” is a candidate key. But, S# alone or P# alone would not uniquely identify a row of the
shipment table.
Primary key
The candidate key that is chosen to perform the identification task is called the primary key and any others are alternate keys
Every tuple must have, by definition, a unique value for its primary key. A primary key which is a combination of more than one attribute is
called a composite primary key
Foreign key
•A foreign key is a “copy” of a primary key that has been exported from one relation into another to represent the existence of a relationship
between them. A foreign key is a copy of the whole of its parent primary key i.e if the primary key is composite, then so is the foreign key
•Foreign key values do not (usually) have to be unique
•Foreign keys can also be null
•A composite foreign key cannot have some attribute(s) null and others non-null
Overlapping candidate keys: Two candidate keys overlap if they involve any attribute in common. For e.g, in an Employee table, E#,Ename
and Emailid, Ename are two overlapping candidate keys. (they have Ename in common)
Attribute that does not participate in any candidate key is called a Non-key attribute
21
Conceptual design
22
Data modeling
ER/CORP/CRS/DB07/003
Copyright © 2004, 23
Infosys Technologies Ltd Version No: 2.0
23
Design levels of a database
Conceptual design
Logical design
ER/CORP/CRS/DB07/003
Copyright © 2004, 24
Infosys Technologies Ltd Version No: 2.0
The outcome of each stage is correspondingly called the conceptual schema, the database schema
and the physical design
24
ER modeling
ER modeling : A graphical technique for understanding and organizing the
data independent of the actual database implementation
Entity: Any thing that may have an independent existence and about which
we intend to collect data.
Also known as Entity type.
ER/CORP/CRS/DB07/003
Copyright © 2004, 25
Infosys Technologies Ltd Version No: 2.0
25
Attributes
The set of possible values for an attribute is called the domain of the attribute
Example:
– The domain of attribute marital status is just the four values: single, married,
divorced, widowed
– The domain of the attribute month is the twelve values ranging from January to
December
Key attribute: The attribute (or combination of attributes) that is unique for
every entity instance
– E.g the account number of an account, the employee id of an employee etc.
ER/CORP/CRS/DB07/003
Copyright © 2004, 26
Infosys Technologies Ltd Version No: 2.0
26
Simple Vs composite attribute
Simple attribute: cannot be divided into simpler components
E.g age of an employee
ER/CORP/CRS/DB07/003
Copyright © 2004, 27
Infosys Technologies Ltd Version No: 2.0
27
Single Vs Multi-valued Attributes
Single valued : can take on only a single value for each entity instance
E.g. age of employee. There can be only one value for this
ER/CORP/CRS/DB07/003
Copyright © 2004, 28
Infosys Technologies Ltd Version No: 2.0
28
Stored Vs Derived attribute
Stored Attribute: Attribute that need to be stored permanently.
ER/CORP/CRS/DB07/003
Copyright © 2004, 29
Infosys Technologies Ltd Version No: 2.0
29
Regular Vs. Weak entity type
Weak entity: Entity that depends on other entity for its existence and doesn’t
have key attribute of its own
ER/CORP/CRS/DB07/003
Copyright © 2004, 30
Infosys Technologies Ltd Version No: 2.0
The spouse data is identified with the help of the employee id to which it is related
30
Relationships
A relationship type between two entity types defines the set of all
associations between these entity types
ER/CORP/CRS/DB07/003
Copyright © 2004, 31
Infosys Technologies Ltd Version No: 2.0
E.g if Works-for is the relationship between the Employee entity and the department entity, then Ram
works for Comp.sc department, shyam works –for electrical department ..etc are relationship instances
of the relationship, works-for
31
Degree of a Relationship
Degree: the number of entity types involved
• One Unary
• Two Binary
• Three Ternary
ER/CORP/CRS/DB07/003
Copyright © 2004, 32
Infosys Technologies Ltd Version No: 2.0
32
Cardinality
Relationships can have different connectivity
– one-to-one (1:1)
– one-to-many (1:N)
– many-to-many (M:N)
ER/CORP/CRS/DB07/003
Copyright © 2004, 33
Infosys Technologies Ltd Version No: 2.0
The minimum and maximum values of this connectivity is called the cardinality of the
relationship
33
Relationship Participation
Total : Every entity instance must be connected through the relationship to
another instance of the other participating entity types
ER/CORP/CRS/DB07/003
Copyright © 2004, 34
Infosys Technologies Ltd Version No: 2.0
34
ER modeling -Notations
35
Entity
Usually a noun in singular
Represented by a rectangle with a label
First letter in capitals
Employee
ER/CORP/CRS/DB07/003
Copyright © 2004, 36
Infosys Technologies Ltd Version No: 2.0
36
Attributes
DOB
Name Address
E# Employee Designation
ER/CORP/CRS/DB07/003
Copyright © 2004, 37
Infosys Technologies Ltd Version No: 2.0
37
Key attribute
DOB
Name Address
E# Designation
Employee
ER/CORP/CRS/DB07/003
Copyright © 2004, 38
Infosys Technologies Ltd Version No: 2.0
38
Multivalued Attribute
DOB
Address
Name
Designation
E#
Employee
skill set
ER/CORP/CRS/DB07/003
Copyright © 2004, 39
Infosys Technologies Ltd Version No: 2.0
39
Composite attribute
floor building
DOB
Name Address
E# Designation
Employee
ER/CORP/CRS/DB07/003
Copyright © 2004, 40
Infosys Technologies Ltd Version No: 2.0
Represented by an ellipse from which other ellipses emanate and represent the component
attributes. E.g Address
40
Relationship
enrols
student course
in
ER/CORP/CRS/DB07/003
Copyright © 2004, 41
Infosys Technologies Ltd Version No: 2.0
•It has a label that explains the relationship. Usually the convention is to read the ER diagram from
top to bottom and from left to right.
•So, the relationship name is so chosen as to make sense when read from left to right.
41
Unary Relationship
Manages
Employee
ER/CORP/CRS/DB07/003
Copyright © 2004, 42
Infosys Technologies Ltd Version No: 2.0
•A unary relationship is represented as a diamond which connects one entity to itself as a loop.
•The relationship above means, some instances of employee manage other instances of Employee.
42
Role names
Role names may be added to make the meaning more explicit
subordinate
Manages
Employee
Manager
ER/CORP/CRS/DB07/003
Copyright © 2004, 43
Infosys Technologies Ltd Version No: 2.0
43
Binary Relationship
ER/CORP/CRS/DB07/003
Copyright © 2004, 44
Infosys Technologies Ltd Version No: 2.0
44
Ternary Relationship
Medicine
ER/CORP/CRS/DB07/003
Copyright © 2004, 45
Infosys Technologies Ltd Version No: 2.0
45
1:1 relationship
1:1
PERSONS Sits_on CHAIR
• P1 • C1
• P2 • C2
• P3 • C3
• P4 • C4
ER/CORP/CRS/DB07/003
Copyright © 2004, 46
Infosys Technologies Ltd Version No: 2.0
One instance of entity type 1 is connected to exactly one other entity instance of entity type 2
46
1:m relationship
1:M
1 m
DEPT EMPLOYS EMPLOYEE
• D1 • E1
•E3
• D2 • E2
•E8 •E7
• D3 • E4
•E5
• D4 • E6
ER/CORP/CRS/DB07/003
Copyright © 2004, 47
Infosys Technologies Ltd Version No: 2.0
47
M:1 relationship • L1 • C1
•L3
• L2 • C2
•L8
• L4 • C3
•L5
Street
Name City
Number Amount
Borrowed_by
Customer
Loan
ER/CORP/CRS/DB07/003
Copyright © 2004, 48
Infosys Technologies Ltd Version No: 2.0
48
M:N relationship
M:N
M N
STUDENTS Taught_by TEACHERS
• S1 • T1
•S3 •T3
• S2 • T2
•S8 •S7 •T8 •T7
• S4 • T4
•S5• S6 •T5
• T6
ER/CORP/CRS/DB07/003
Copyright © 2004, 49
Infosys Technologies Ltd Version No: 2.0
49
Summary
ER/CORP/CRS/DB07/003
Copyright © 2004, 50
Infosys Technologies Ltd Version No: 2.0
50
Thank You!
ER/CORP/CRS/DB07/003
Copyright © 2004, 51
Infosys Technologies Ltd Version No: 2.0
51