DBMS Unit 2
DBMS Unit 2
(DBMS)
Unit -2
Data Base Management System
Data: Data is the basic raw facts and figures
Ex: a name, a digit, a picture etc.
❖Corporate
❖Airlines
❖Hotels
❖Banks
❖Colleges /University
❖Railway reservation
❖Telecommunication Industry
❖Data mining
❖Libraries
Advantages of Using DBMS
❖ No Data Redundancy
❖ Data Consistency
❖ Mass Data Storage
❖ Centralized Access
❖ Automatic Backup Possible
❖ Data Recovery Possible
❖ Integrity Constraints
❖ Easily updating & fetching of data
❖ Only authorized Access
Disadvantages of Flat File Systems
user
Applications/queries
Query processor
Storage manager
metadata data
•Examples:
•Entity-Relationship Model
•Relational Model
•Object-Oriented Model (e.g., ODL)
Different Data Models
❖ Flat file
❖ Hierarchical Data Model
❖ Network Data model
❖ Relational Data model
Features of Flat Files
A flat file database is a type of database that stores data in a single
table or a file. Placing data in a flat file offers following advantages:
Attributes
192-83-7465 Johnson
Alma Palo Alto A-101
019-28-3746 Smith
North Rye A-215
192-83-7465 Johnson
Alma Palo Alto A-201
321-12-3123 Jones
Main Harrison A-217
019-28-3746 Smith
North Rye A-201
Sample Relational Database
Schema
The overall design of the database is called the
database schema.
Tuple : Record
Attributes: columns
Entity : Tables
Entity/Relationship (E/R) Model
• Entities: objects
• Relationships: associate entities
• Roles of entities in a relationship
• Constraints on entities:
– domain constraints
– key constraints
• Constraints on relationships:
– Cardinality constraints
– Participation constraints
– Weak Entity Sets
• Multiway relationships
• Subclass/superclass Relationships
• Aggregation
Symbols Used in E-R Notation
Entities and Entity Sets
• Entities:
– nouns, “things” in the world
– Have attributes: course name, id, address, dept,
age, room, …
• Entity sets: a set of entities
Attributes
• Single-valued versus multi-valued:
– “telephone number”: multi-valued
– “Salary”: single-valued
• Atomic versus composite:
– “Age”: atomic
– “Address”: composite
• Derived versus stored:
– Derived: derived from other attributes or entities,
e.g., “age” derived from “date of birth.”
– Stored: all other attributes
Relationships
• Relationship: association of multiple entities
• Relationship Set:
– set of relationships over the same entity sets
– binary, ternary, 4-nary, …n-nary
Custom-Account account
customer Relationship set
259, 10K
Tom, 62900, Main, LA
305,
Jane, 62901, North, 20K
Irvine 245,
2400
age
Customer custacct Account
dob
tel
opendate
numb
er type time name
addr
Stops
trains stations
At
engin
eer type
Problem: does not capture the constraints that express trains only stop only at
express stations and local trains stop at all local stations
Design 2: good
numbe enginee
r r
train
tim nam
e e addres
d I
s
S
A StopsAt stations
local trains
2
I
d
S
express trains tim A
e
• Main idea:
– Table: relation
– Column header: attribute
– Row: tuple
• Relational schema: name(attributes)
– Example: employee(ssno,name,salary)
• Attributes:
– Each attribute has a domain – domain constraint
– Each attribute is atomic: we cannot refer to or directly see a subpart
of the value.
Relation Example
Account Customer
violations
Key Constraints
• Key:
– Minimal superkey (no proper subset is a superkey)
– If more than one key: choose one as a primary key
• Example:
– Key 1: LogID (primary key)
– Key 2: AccountId, Xact#
– Superkeys: all supersets of the keys
Log(LogId, AccountId, Xact#, Time, Ammount)
OK
Integrity Rules
There are two Integrity Rules that every relation
should follow :
1. Entity Integrity (Rule 1)
2. Referential Integrity (Rule 2)
r
s
S R
There are two referential integrity constraint:
• Insert Constraint: Value cannot be inserted in
child table if the value is not lying in parent
table.
• Delete Constraint: value cannot be deleted
from parent table if the value is lying in child
data.
Examples of Referential Integrity
Account Customer
Account.customerId to Customer.Id
Student Dept