0% found this document useful (0 votes)
5 views

Unit - I - Introduction To DBMS

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Unit - I - Introduction To DBMS

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 80

“Database Management”

TE ( E & TC ) 2019 Course


OUTLINE

 Course Details
 Course Outcomes and Course Objectives
Course Details

 Course Code and Name


❖ 304183: Database Management
 Prerequisite Course
❖ Data Structures
 Teaching Scheme
❖ Theory: 03 hrs. / week
 Credits: 03
 Examination Scheme
❖ In-Sem (Theory): 30 Marks
❖ End Sem (Theory): 70 Marks
Course Outcomes and Course Objectives
(Unit I and Unit III)
 Course Objectives:
❖ To understand fundamental concepts of database from its design to its
implementation.
❖ To analyze database requirements and determine the entities involved in the
system and with one another.
❖ To manipulate database using SQL Query to create, update and manage Database.

 Course Outcomes:
❖ To implement the underlying concepts of a database system.
❖ Formulate, using SQL/DML/DDL commands, solutions to a wide range of query and
update problems.
Unit I: Introduction to DBMS
Introduction to Database Management Systems, Purpose of
Database Systems, Database-System Applications, Data
Abstraction and Database System Structure.
Relational Model: Structure of relational databases, Domains,
Relations, Relational algebra – fundamental operators and syntax,
relational algebra queries, tuple relational calculus.
Entity-Relationship model: Basic Concepts, Entity Set,
Relationship Sets and Weak Entity Sets, Mapping Cardinalities,
Keys, E-R diagrams, Design Issues, Extended E-R Features,
Converting E-R & EER diagram into tables.
Unit I: Introduction to DBMS

 Introduction to Database Management Systems


 Purpose of Database Systems
 Database-System Applications
 Data Abstraction
 Database System Structure
Introduction to Database Management Systems

 DBMS contains information about a particular


enterprise.
❖ Collection of interrelated data
❖ Set of programs to access those data
 The primary goal of a DBMS is
❖ to provide a way to store and retrieve database information that is
both convenient and efficient use of data of the enterprise.
Introduction to Database Management Systems

 Database Applications
 Banking: Transactions
 Airlines: reservations, schedules
 Universities: registration, grades
 Sales: customers, products, purchases
 Online retailers: order tracking, customized recommendations
 Manufacturing: production, inventory, orders, supply chain
 Human resource: employee records, salaries, tax deductions
 ……
Introduction to Database Management Systems

 University Database Example


 Add new students, instructors and courses
 Register students for courses and compute grade point averages
(GPA) and generate transcripts
Purpose of Database Systems

Drawbacks of using file systems to store data


➢ In the early days, database applications were built directly on top of
file systems, which leads to:
➢ Data redundancy and inconsistency: data is stored in multiple file
formats resulting in duplication of information in different files
➢ Difficulty in accessing data
❖ Need to write a new program to carry out each new task
➢ Data isolation
❖ Multiple files and formats
➢ Integrity problems
❖ Integrity constraints (e.g., account balance > 0) become “buried”
in program code rather than being stated explicitly
❖ Hard to add new constraints or change existing ones
Purpose of Database Systems
Drawbacks of using file systems to store data (Cont.)
➢ Atomicity of updates
❖ Failures may leave database in an inconsistent state with partial updates
carried out
❖ Example: Transfer of funds from one account to another should either complete or not
happen at all

➢ Concurrent access by multiple users


❖ Concurrent access needed for performance
❖ Uncontrolled concurrent accesses can lead to inconsistencies
❖ Ex: Two people reading a balance (say 50) and updating it by withdrawing money (say 50
each) at the same time

➢ Security problems
❖ Hard to provide user access to some, but not all, data
Database-System Applications

➢ Enterprise Information: Sales, Accounting, Human Resource,


Manufacturing, Online retailers
➢ Banking and Finance: Banking, Credit card transactions, Finance
➢ Universities
➢ Airlines
➢ Telecommunication: For keeping records of calls made, generating
monthly bills, maintaining balances on prepaid calling cards, and
storing information about the communication networks
Course Textbook

Database System Concepts


Seventh Edition
Avi Silberschatz
Henry F. Korth
S. Sudarshan
McGraw-Hill
ISBN 9780078022159
View of Data

 A database system is a collection of interrelated data and a set of


programs that allow users to access and modify these data.
 A major purpose of a database system is to provide users with an
abstract view of the data.
Data Abstraction

 Physical level: describes how a record (e.g., instructor) is stored.


 Logical level: describes data stored in database, and the relationships
among the data.
 type instructor = record
ID : string;
name : string;
dept_name : string;
salary : integer;
end;
Physical Data Independence – the ability to modify the physical schema without
changing the logical schema

 View level: application programs hide details of data types. Views


can also hide information (such as an employee’s salary) for security
purposes.
Data Abstraction
• Levels of abstraction
Schema and Instance
data Models
SQL
Database Design

Schema and Instance


Schemas and Instances
• Similar to types and variable in programming languages
• Schemas:
• Logical Schemas- the overall logical structure of the database
• Analogous to type information of a variable in program
• Example: The database consists of information about a set of customers
and accounts in a bank and relationship between them.
• Customer Schema
Name Customer ID Account Aadhaar ID Mobile

• Account Schema

Account Account type Interest rate Min bal balance

• Physical Schemas – the overall physical structure of the database


Schemas and Instances
 Instances
 The actual content of the database at a particular point in time
 Analogous to the value of a variable
 Customer Instance
Name Customer ID Account No Aadhaar ID Mobile no
Pavan Laha 6728 917322 182719289372 9830234578
Lata Kala 8912 827183 918291204829 71897203522
Nand Prabhu 6617 372912 127872914021 8890290220

 Account Instance
Account No Account Type Interest Rate Min.bal Balance
917322 Savings 4.0% 5000 7812
827183 Current 0.0% 0 291820
372912 Term Deposit 6.75% 10000 100000
Schemas and Instances

 Physical Data independences – the ability to modify the physical schema


without changing the logical schema
 Analogous to independence of ‘interface’ and ‘Implementation’ in object
oriented systems
 Application depend on the logical schema
 In general, the interface between the various levels and components
should be well defined so that the changes in some parts do not seriously
influence others.
• Levels of abstraction
Schema and Instance
data Models
SQL
Database Design

Data Models
Data Models
 The structure of the database is called data model.
 A collection of tools for describing
 Data
 Data relationships
 Data semantics
 Data constraints
 Relational Model (we focus in this)
 Entity relationships data models (mainly for database design)
 Object based data models (object oriented and object related)
 Semi-structured data model (XML)
Database System Structure: Database Users
Database System Structure: Architecture
Quiz 1: Scratch Your Head?

https://forms.office.com/r/gj3r9N6Tbk
Relational Model

 Structure of relational databases


 Domains
 Relations
 Relational algebra
 Fundamental operators and syntax
 Relational algebra queries
 Tuple relational calculus
Relational Model: Structure of relational databases

 All the data is stored in various tables.


 Example of tabular data in the relational model Columns

Rows
Relational Model: Structure of relational databases
Relational Model: Structure of relational databases

Example of a Instructor Relation attributes


(or columns)

tuples
(or rows)
Relational Model: Structure of relational databases

➢ Relation Schema and Instance:


❖ A1, A2, …, An are attributes
❖ R = (A1, A2, …, An ) is a relation schema
Example:
instructor = (ID, name, dept_name, salary)
❖ A relation instance r defined over schema R is denoted by r (R).
❖ The current values a relation are specified by a table
❖ An element t of relation r is called a tuple and is represented by
a row in a table
Relational Model: Attributes and Domains

➢ The set of allowed values for each attribute is called the domain of
the attribute
➢ Attribute values are (normally) required to be atomic; that is,
indivisible
➢ The special value null is a member of every domain. Indicated that
the value is “unknown”
➢ The null value causes complications in the definition of many
operations
Relational Model: Relational Algebra

➢ A procedural language consisting of a set of operations that take one


or two relations as input and produce a new relation as their result.
➢ Six basic operators
❖ select: 
❖ project: 
❖ union: 
❖ set difference: –
❖ Cartesian product: x
❖ rename: 
Relational Model: Relational Algebra & Queries

➢ Select Operation
➢ The select operation selects tuples that satisfy a given predicate.

➢ Notation:  p (r)
➢ p is called the selection predicate
➢ Example: select those tuples of the instructor relation where the
instructor is in the “Physics” department.
➢ Query

 dept_name=“Physics” (instructor)

➢ Result
Select Operation – selection of rows (tuples)

▪ Relation r

▪A=B ^ D > 5 (r)

▪A≠B (r)
▪C > 0 (r)
▪ D <1 (r)
Relational Model: Relational Algebra & Queries
➢ We allow comparisons using
=, , >, , <, 
in the selection predicate.
➢ We can combine several predicates into a larger predicate by using the
connectives:
 (and),  (or),  (not)
➢ Example: Find the instructors in Physics with a salary greater $90,000, we write:

 dept_name=“Physics”  salary > 90,000 (instructor)


➢ The select predicate may include comparisons between two attributes.
Example, find all departments whose name is the same as their building name:

 dept_name=building (department)
Relational Model: Relational Algebra & Queries

➢ Project Operation
➢ A unary operation that returns its argument relation, with certain
attributes left out.
Notation:

 A1,A2,A3 ….Ak (r)


where A1, A2, …, Ak are attribute names and r is a relation name.
➢ The result is defined as the relation of k columns obtained by
erasing the columns that are not listed
➢ Duplicate rows removed from result, since relations are sets
Project Operation – selection of columns (Attributes)

▪ Relation r:

▪ A,C (r)
Relational Model: Relational Algebra & Queries

➢ Project Operation
➢ Example: eliminate the dept_name attribute of instructor

➢ Query: ID, name, salary (instructor)


➢ Result:
Relational Model: Relational Algebra & Queries

➢ Union Operation (Same for Intersection and Difference)


➢ The union operation allows us to combine two relations
Notation: r  s
➢ For r  s to be valid.
1. r, s must have the same arity (same number of attributes)
2. The attribute domains must be compatible (example: 2nd
column of r deals with the same type of values as does the
2nd column of s)
➢ Example: to find all courses taught in the Fall 2017 semester, or in the Spring
2018 semester, or in both

course_id ( semester=“Fall” Λ year=2017 (section)) 

course_id ( semester=“Spring” Λ year=2018 (section))


Union of two relations

▪ Relations r, s:

▪ r  s:
Set difference of two relations
▪ Relations r, s:

▪ r – s:
Set intersection of two relations
▪ Relation r, s:

▪ rs

Note: r  s = r – (r – s)
Relational Model: Relational Algebra & Queries

➢ Composition of Relational Operations


➢ The result of a relational-algebra operation is relation and therefore of
relational-algebra operations can be composed together into a relational-
algebra expression.
➢ Consider the query -- Find the names of all instructors in the Physics
department.

name( dept_name =“Physics” (instructor))

➢ Instead of giving the name of a relation as the argument of the projection


operation, we give an expression that evaluates to a relation.
Relational Model: Relational Algebra & Queries

➢ Cartesian-Product Operation
➢ The Cartesian-product operation (denoted by X) allows us to combine
information from any two relations.
➢ Example: the Cartesian product of the relations instructor and teaches is
written as:

instructor X teaches
➢ We construct a tuple of the result out of each possible pair of tuples: one from
the instructor relation and one from the teaches relation (see next slide)
➢ Since the instructor ID appears in both relations we distinguish between these
attribute by attaching to the attribute the name of the relation from which
the attribute originally came.
instructor.ID
teaches.ID
Joining two relations -- Cartesian-product
▪ Relations r, s:

▪ r x s:
Cartesian-product – naming issue
▪ Relations r, s: B

▪ r x s: r.B s.B
Renaming a Table
▪ Allows us to refer to a relation, (say E) by more than one name.
 x (E)

returns the expression E under the name X

▪ Relations r

▪ r x  s (r) r.A r.B s.A s.B


α 1 α 1
α 1 β 2
β 2 α 1
β 2 β 2
Relational Model: Relational Algebra & Queries

➢ Join Operation
➢ The Cartesian-Product
instructor X teaches
associates every tuple of instructor with every tuple of teaches.
➢ Most of the resulting rows have information about instructors who did NOT
teach a particular course.
➢ To get only those tuples of “instructor X teaches “ that pertain to instructors
and the courses that they taught, we write:

 instructor.id = teaches.id (instructor x teaches ))

➢ We get only those tuples of “instructor X teaches” that pertain to instructors


and the courses that they taught.
➢ The result of this expression, shown in the next slide
Relational Model: Relational Algebra & Queries
Joining two relations – Natural Join
▪ Let r and s be relations on schemas R and S respectively.
Then, the “natural join” of relations R and S is a relation on
schema R  S obtained as follows:
▪ Consider each pair of tuples tr from r and ts from s.
▪ If tr and ts have the same value on each of the attributes in
R  S, add a tuple t to the result, where
t has the same value as tr on r
t has the same value as ts on s
Natural Join Example
▪ Relations r, s:

▪ Natural Join
n r s

 A, r.B, C, r.D, E ( r.B = s.B ˄r.D = s.D (r x s)))


Summary of Relational Algebra Operators
Symbol (Name) Example of Use
σ
σ salary > = 85000 (instructor)
(Selection
)
Return rows of the input relation that satisfy the predicate.
Π
(Projection) Π ID, salary (instructor)
Output specified attributes from all rows of the input relation.
Remove duplicate tuples from the output.
x
(Cartesian Product) instructor x department

Output pairs of rows from the two input relations that have the same value
on all attributes that have the same name.

(Union) Π name (instructor) ∪ Π name (student)

Output the union of tuples from the two input relations.


-
(Set Difference) Π name (instructor) ‐ ‐ Π name (student)

Output the set difference of tuples from the two input relations.

(Natural Join) instructor ⋈ department

Output pairs of rows from the two input relations that have the same value
on all attributes that have the same name.
Notes about Relational Languages

▪ Each Query input is a table (or set of tables)


▪ Each query output is a table
▪ All data in the output table appears in one of the input tables
▪ Relational Algebra is not Turning complete
Summary

▪ Introduced relational algebra


▪ Familiarize with the operators of relational
algebra
Relational Model: Tuple Relational Calculus

➢ Query has the form: {T | p(T)}


p(T) denotes a formula in which tuple variable T appears.
➢ Answer is the set of all tuples T for which the formula p(T)
evaluates to true.
➢ Formula is recursively defined:
➢ start with simple atomic formulas (get tuples from relations or
make comparisons of values)
t[A]
t r
➢ build bigger and better formulas using the logical connectives.
Relational Model: Tuple Relational Calculus

➢ Selection and projection Operators- to select required data


from the table
Student Roll_No Name City Marks
101 Om Mumbai 75
102 Shubham Pune 50
104 Aditya Solapur 67
103 Mrunal Solapur 80

1. Select al tuples from student table Roll_No Name City Marks


{t |t Student} 101 Om Mumbai 75
103 Mrunal Solapur 80
2. Select all students having marks >70
{t |t student  t[Marks]>70}
Relational Model: Tuple Relational Calculus

➢ Query to Select some attributes of the table


➢ We can construct the notation from “ there exist”
Roll_No Name City Marks
t r [ Q(t)]
101 Om Mumbai 75
102 Shubham Pune 50
1. Select Roll_No for each student from 104 Aditya Solapur 67
student relation 103 Mrunal Solapur 80

{t |  t student(t[Roll_No]=s[Roll_No] }
Roll_No
Roll_No
101
102
2. Select Roll_No for each student having 102
104
marks<70 from student relation 104
103
{t |  t student (t [Roll_No]=s [Roll_No] s[Marks]<70) }
Relational Model: Tuple Relational Calculus
• Find the ID, name, dept_name, salary for all instructors whose
salary is greater than 80000
{t |t instructor  t[salary]>80000}

– Modify this query to answer: Find ID attribute


t r [ Q(t)]
– Find the instructor ID for each instructor with salary greater than
80000

{t |  t instructor ( t[ID] = S[ID]  S[salary] > 800000) }

Note, here t is a tuple variable of 3 fields (i.e. {t} is a projection of


instructor), since only 3 fields are ever mentioned and t is never used to
range over any relations in the query.
Relational Model: Tuple Relational Calculus
• Find the names of all instructor whose department is in
Watson building

{t |  t instructor ( t[name] = S[name]


  u  department( u[dept_name] = S[dept_name]
 u [building] = “Watson” )) }
1. Complex query since it involves two relations
2. Two there exist clauses in expression
3. Tuple variable u is restricted to departments that are located in
Watson building
4. Tuple variable S is restricted to instructors whose dept_name
matches that of tuple variable u
Name
Einstein
Crick
Gold
Quiz 2: Scratch Your Head?

https://forms.office.com/r/5wzVe3A7JV
Entity-Relationship model: Basic Concepts

➢ Database Design
➢ Design Phases
➢ Initial phase of database design – is to characterize the needs of
database users. Outcome- specifications of user requirements.
➢ To choose data model and apply concepts of data model
translates these requirements into a conceptual schema.(E-R
model)
➢ Conceptual schema- Specifies entities, attributes,
relationship among those entities and constraints.
➢ Result- Creation of E-R diagram
➢ Specification of functional requirement
Entity-Relationship model: Basic Concepts

➢ Database Design
➢ Design Phases
➢ Initial phase of database design
➢ To choose data model and apply concepts of data model translates these
requirements into a conceptual schema.(E-R model)
➢ Specification of functional requirement
➢ Implementation of database
➢ Logical Design Phase
➢ Physical Design Phase
➢ In designing database schema, it is necessary to avoid two major problems
: Redundancy and Incompleteness
Entity-Relationship model: Basic Concepts

➢ Entity Relationship Model


➢ Models an enterprise as a collection of entities and relationships
❖ Entity: a “thing” or “object” in the enterprise that is
distinguishable from other objects
❖ Described by a set of attributes
❖ Relationship: an association among several entities
➢ Represented diagrammatically by an entity-relationship diagram
Entity-Relationship model: Basic Concepts

➢ The ER data mode was developed to facilitate database design by allowing


specification of an enterprise schema that represents the overall logical structure
of a database.
➢ The ER data model employs three basic concepts:
❖ 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.


Entity-Relationship model: Entity Sets

➢ An entity is an object that exists and is distinguishable from other objects.


Example: specific person, company, event, plant
➢ 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.
Entity-Relationship model: Entity Sets

Entity Sets -- instructor and student

Representing Entity Sets


Entity-Relationship model: Relationship Sets

➢ A relationship is an association among several entities


Example:
44553 (Peltier) advisor 22222 (Einstein)
student entity relationship set instructor entity
➢ A relationship set is a mathematical relation among n  2 entities, each taken
from entity sets
{(e1, e2, … en) | e1  E1, e2  E2, …, en  En}
where (e1, e2, …, en) is a relationship
Example:
(44553,22222)  advisor
Entity-Relationship model: Relationship Sets

➢ Example: we define the relationship set advisor to denote the


associations between students and the instructors who act as their
advisors.

➢ Pictorially, we draw a line between related entities.


Entity-Relationship model:
Representing Relationship Sets via ER Diagrams

➢ Diamonds represent relationship sets.


Entity-Relationship model

➢ Attribute types:
➢ Simple and composite attributes.
➢ Single-valued and multivalued attributes
➢ Example: multivalued attribute: phone_numbers
➢ Derived attributes
➢ Can be computed from other attributes
➢ Example: age, given date_of_birth
➢ Domain – the set of permitted values for each attribute
Entity-Relationship model: Weak Entity Sets

➢ A weak entity set is one whose existence is dependent on another entity,


called its identifying entity
➢ Instead of associating a primary key with a weak entity, we use the
identifying entity, along with extra attributes called discriminator to
uniquely identify a weak entity.
➢ An entity set that is not a weak entity set is termed a strong entity set.
➢ Every weak entity must be associated with an identifying entity; that is, the
weak entity set is said to be existence dependent on the identifying entity
set.
➢ The identifying entity set is said to own the weak entity set that it
identifies.
Entity-Relationship model: Weak Entity Sets

➢ The relationship associating the weak entity set with the identifying entity
set is called the identifying relationship.
➢ Note that the relational schema we eventually create from the entity set
section does have the attribute course_id, for reasons that will become clear
later, even though we have dropped the attribute course_id from the entity
set section.

➢ Primary key for section – (course_id, sec_id, semester, year)


Entity-Relationship model: Mapping Cardinality Constraints

➢ Express the number of entities to which another entity can be associated via a
relationship set.
➢ 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
Entity-Relationship model: Primary key for Entity Sets

➢ By definition, individual entities are distinct.


➢ From database perspective, the differences among them must be expressed in terms of
their attributes.
➢ The values of the attribute values of an entity must be such that they can uniquely
identify the entity.
❖ No two entities in an entity set are allowed to have exactly the same value for all
attributes.
➢ A key for an entity is a set of attributes that suffice to distinguish entities from each other
Entity-Relationship model: E-R Diagram for a University
Enterprise
Entity-Relationship model: Extended E-R Features

➢ Specialization
➢ Top-down design process;
❖ we designate sub-groupings within an entity set that are distinctive from other entities in the set.
➢ These sub-groupings become lower-level entity sets that have attributes or participate
in relationships that do not apply to the higher-level entity set.
➢ Depicted by a triangle component labeled ISA (e.g., instructor “is a” person).
➢ Attribute inheritance – a lower-level entity set inherits all the attributes and
relationship participation of the higher-level entity set to which it is linked.
Entity-Relationship model: Extended E-R Features

➢ Generalization
➢ A bottom-up design process –
❖ combine a number of entity sets that share the same features into a higher-level entity set.
➢ Specialization and generalization are simple inversions of each other;
they are represented in an E-R diagram in the same way.
➢ The terms specialization and generalization are used interchangeably.
Entity-Relationship model: Converting ER to Tables

➢ Convert Entity Sets, Relationships to tables


➢ Convert all attributes to columns
➢ Assign all Primary attributes of Entity Sets to Relationship table as coloumns
Quiz 3: Scratch Your Head?

https://forms.office.com/r/ytRZ9xyJjX

You might also like