DBMS_ENDSEM
DBMS_ENDSEM
Presented By:-
Dr. Sanjeev Sharma
Introduction
• Data: Known facts that can be recorded and have an
implicit meaning.
Presented By:-
Dr. Sanjeev Sharma
Manages Interaction Between end
Users and Database
Example of a Database
Mini-world for the example: Part of a UNIVERSITY environment.
Some mini-world entities (Data elements):
- STUDENTs
- COURSEs
- SECTIONs (of COURSEs)
- (academic) DEPARTMENTs
- INSTRUCTORs
Some mini-world relationships:
- SECTIONs are of specific COURSEs
- STUDENTs take SECTIONs
- COURSEs have prerequisite COURSEs
- INSTRUCTORs teach SECTIONs
- COURSEs are offered by DEPARTMENTs
- STUDENTs major in DEPARTMENTs
Schema and Instances
• Similar to types and variables in programming languages
• Schema – the logical structure of the database
– Example: The database consists of information about a set
of customers and accounts and the relationship between
them)
– Analogous to type information of a variable in a program
• Instance – the actual content of the database at a particular
point in time
– Analogous to the value of a variable
Data Abstraction in DBMS
• Database systems are made-up of complex data structures. To
ease the user interaction with database, the developers hide
internal irrelevant details from users.
Presented By:-
Dr. Sanjeev Sharma
Database Languages
• A DBMS must provide appropriate languages and interfaces
for each category of users to express database queries and
updates.
Presented By:-
Dr. Sanjeev Sharma
Database Models in DBMS
• A data model is an idea which describes how the data can be
represented and accessed from software system after its
complete implementation.
• It is a simple abstraction of complex real world data gathering
environment.
• It defines data elements and relationships among various data
elements for a specified system.
• The main purpose of data model is to give an idea that how
final system or software will look like after development is
completed.
Various Types of Data Models
• E-R model
• Relational Model
• Hierarchical Model
• Network Model
• Object Based Model
Entity Relationship Model
• Entity relationship model is based on the notion of the real
world entities and their relationships. This model focus on two
main things:
– Entity and their attributes
– Relationships among entities
• An Entity is a thing that can be distinguishable from others.
• An entity has a real world property called attribute and
attribute define by a set of values called domain.
• For example, in a university a student is an entity, university is
the database, name and age and sex are the attributes. The
relationships among entities define the logical association
between entities.
Relational Model
• This model was introduced by E.F Codd in 1970, and
since then it has been the most widely used database
model.
– In this model, data is organised in two-dimensional tables and
the relationship is maintained by storing a common field.
– The basic structure of data in the relational model is tables. All
the information related to a particular type is stored in rows of
that table.
– Hence, tables are also known as relations in relational model.
Hierarchical Model
• This database model organises data into a tree-like-structure,
with a single root, to which all the other data is linked. The
hierarchy starts from the Root data, and expands like a tree,
adding child nodes to the parent nodes.
– In this model, a child node will only have a single parent node.
– Hierarchical model was developed by IBM and North American
Rockwell known as Information Management System.
– It represents the data in a hierarchical tree structure.
– In this model, the data is sorted hierarchically.
– It uses pointer to navigate between the stored data.
Network Data Model
• Network model has the entities which are organized in a
graphical representation and some entities in the graph
can be accessed through several paths.
– Network Database Model is same like Hierarchical Model, but
the only difference is that it allows a record to have more than
one parent.
– In this model, there is no need of parent to child association like
the hierarchical model.
– It replaces the hierarchical tree with a graph.
– It represents the data as record types and one-to-many
relationship.
– This model is easy to design and understand.
Object Model
• Object model stores the data in the form of objects, classes and
inheritance.
• This model handles more complex applications, such as
Geographic Information System (GIS), scientific experiments,
engineering design and manufacturing.
– It is used in File Management System.
– It represents real world objects, attributes and behaviors.
– It provides a clear modular structure.
– It is easy to maintain and modify the existing code.
Attributes
• An entity is represented by a set of attributes. Attributes
are descriptive properties possessed by each member of
an entity set.
– Customer is an entity and its attributes are customerid,
custmername, custaddress etc.
Presented By:-
Dr. Sanjeev Sharma
Keys
• A key is an attribute or set of attributes that is used to identify
data in entity sets. The attributes which are used as key are
known as key attributes. Rest of all are known as Non-key
attributes.
• Types of the Keys
– Super Keys
– Candidate Keys
– Primary Keys
– Alternative Keys
– Foreign Keys
• Super Key : A super key is a set of collection of one or more
than one attributes that can identify data uniquely.
• Any entity set has more than one super key.
Presented By:-
Dr. Sanjeev Sharma
Types of Entity Set
• There are two types of entity sets as given below:
• Strong Entity Sets
– Entity set having any key attributes are known as Strong Entity
sets.
– Ex. The Figure shows strong entity set Student having key
attribute Reg_No.
• Weak Entity Set
• Entity sets having no key attributes are known as Weak Entity
sets.
– Ex. The Figure shows weak entity set Table having no key attributes to
identify the tuples uniquely.
– A weak entity set is always associated with another entity set to make it
meaningful.
• This another entity set is known as Identifying entity set.
• E-R diagrams represents the logical structure of a database.
Symbols used in E-R diagrams are shown in Table.
Example E-R Diagram
Exa
[ 1'Js!ke BmL iE-R dlii8£F aDL havmg two entiity ~b," Cm1il1Dm.e:F 8ID1!1 Irt:eDil.,
Relationship Sets
• Relationship : A relationship is the association among several
entities. It connects different entities through a meaningful
relation.
• Relationship Set : A relationship set is a set of relationships
of the same type.
• Consider an example, employees work in different
departments. Then relationship exists between employees and
departments because each employee must belongs to some
department. Relation of all employees with department when
combined makes the relationship set because each employee
has same kind of relation with departments.
• Here, Employee and Department are two entity sets. r stands
for relationship between Employee and Department. Works_in
is the relationship set as shown in Figure.
Presented By:-
Dr. Sanjeev Sharma
Constraints
• An E-R enterprise scheme may define certain constraints to
which the contents of a database must confirm.
• Mapping cardinalities or cardinality ratios, express the number
of entitities to which another entity can be associated via a
relationship set mapping cardinalities are most useful in
describing binary relationship sets.
• For a binary relationship set R between entity set A and B the
mapping cardinality must be one of the following :
– One to One
– One to Many
– Many to One
– Many to Many
One to one
• One to One (1 : 1) : An entity in X is associated with at most
one entity in Y and an entity in Y is associated with at most
one entity in X.
• A country has only one president. Any person may be the
president of at most one country.
One to Many (1 : N)
• An entity in X is associated with any number of entities in Y.
An entity in Y is associated with at most one entity in X.
• A manager has many employees under it but an employee
works under only one manager
Many to one
• Many to One (N : 1) : An entity in X is associated with at most
one entity in Y. An entity in Y is associated with any number
of entities in X.
• A employee can work on single project while any project can
be assigned to more than one employee.
• Many to Many (M : N) : An entity in X is associated with any
number (zero or more) of entities in Y and vice versa.
• A student can have more than one subject and one subject can
be given to more than one student.
Participation Constraints
• It tells the participation of entity set in relationship sets.
• There are two types of participations.
– Partial Participation
– Total Participation
• Partial Participation
• Partial participation : If only some entities from entity set E is
participated in relationships in set R then it is known as Partial
participation. Partial participation is shown in Figure (a).
• Total participation : If every entity from entity set E is
participated with at least one relation in relationship set R then
it is known as Total participation.
• Consider the Figure (b). Here Customer and Loan are two
entity sets and Relationship set is Borrower.
– Every customer may or may not take the Loan so Customer entity set is
partially participated.
– But every loan is concerned with at least one customer of bank. So
Loan entity set is totally participated.
Partial vs Total Participation
Reduction of E-R diagram to Table
• To represent the database in tabular form, E-R diagrams have
to be reduced in tables.
– Rule-01: For Strong Entity Set With Only Simple Attributes
– Rule-02: For Strong Entity Set With Composite Attributes-
– Rule-03: For Strong Entity Set With Multi Valued Attributes
– Rule-04: Translating Relationship Set into a Table-
– Rule-05: For Binary Relationships With Cardinality Ratios-
– Rule-06: For Binary Relationship With Both Cardinality
Constraints and Participation Constraints-
– Rule-07: For Binary Relationship With Weak Entity Set-
Rule-01
• For Strong Entity Set With Only Simple Attributes
• A strong entity set with only simple attributes will require only
one table in relational model.
– Attributes of the table will be the attributes of the entity set.
– The primary key of the table will be the key attribute of the entity set.
Rule -02
• For 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 composite attributes
are taken into account and not the composite attribute itself.
Rule-03
• For Strong Entity Set With Multi Valued Attributes
• A strong entity set with any number of multi valued attributes
will require two tables in relational model.
• One table will contain all the simple attributes with the
primary key.
• Other table will contain the primary key and all the multi
valued attributes.
Thank You
Database Management System
Presented By:-
Dr. Sanjeev Sharma
Reduction of E-R diagram to Table
• To represent the database in tabular form, E-R diagrams have
to be reduced in tables.
– Rule-01: For Strong Entity Set With Only Simple Attributes
– Rule-02: For Strong Entity Set With Composite Attributes-
– Rule-03: For Strong Entity Set With Multi Valued Attributes
– Rule-04: Translating Relationship Set into a Table-
– Rule-05: For Binary Relationships With Cardinality Ratios-
– Rule-06: For Binary Relationship With Both Cardinality
Constraints and Participation Constraints-
– Rule-07: For Binary Relationship With Weak Entity Set-
Rule-01
• For Strong Entity Set With Only Simple Attributes
• A strong entity set with only simple attributes will require only
one table in relational model.
– Attributes of the table will be the attributes of the entity set.
– The primary key of the table will be the key attribute of the entity set.
Rule -02
• For 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 composite attributes
are taken into account and not the composite attribute itself.
Rule-03
• For Strong Entity Set With Multi Valued Attributes
• A strong entity set with any number of multi valued attributes
will require two tables in relational model.
• One table will contain all the simple attributes with the
primary key.
• Other table will contain the primary key and all the multi
valued attributes.
Rule-04:
• Translating Relationship Set into a Table-
• A relationship set will require one table in the relational model.
• Attributes of the table are-
– Primary key attributes of the participating entity sets
– Its own descriptive attributes if any.
• Set of non-descriptive attributes will be the primary key.
Rule-5
• Rule-05: For Binary Relationships With Cardinality
Ratios-
– Case-01: Binary relationship with cardinality ratio m:n
– Case-02: Binary relationship with cardinality ratio 1:n
– Case-03: Binary relationship with cardinality ratio m:1
– Case-04: Binary relationship with cardinality ratio 1:1
• Case-01: For Binary Relationship With Cardinality Ratio
m:n
• Case-02: For Binary Relationship With
Cardinality Ratio 1:n
• Case-03: Binary relationship with cardinality ratio m:1
• Case-04: Binary relationship with cardinality ratio 1:1
Converting Ternary Relationship to
Tables
• The primary key attributes – Patient ID, Physician ID, and
Treatment Code – become foreign keys in PATIENT
TREATMENT. These attributes are components of the primary
key of PATIENT TREATMENT.
Thumb Rules to Remember
• While determining the minimum number of tables required
for binary relationships with given cardinality ratios,
following thumb rules must be kept in mind-
• For binary relationship with cardinality ration m : n ,
separate and individual tables will be drawn for each entity
set and relationship.
• For binary relationship with cardinality ratio either m : 1 or
1 : n , always remember “many side will consume the
relationship” i.e. a combined table will be drawn for many
side entity set and relationship set.
• For binary relationship with cardinality ratio 1 : 1 , two
tables will be required. You can combine the relationship set
with any one of the entity sets.
• Rule-06: For Binary Relationship With Both Cardinality
Constraints and Participation Constraints-
• Cardinality constraints will be implemented as discussed in
Rule-05.
• Because of the total participation constraint, foreign key
acquires NOT NULL constraint i.e. now foreign key can not
be null.
• Case-01: For Binary Relationship With Cardinality
Constraint and Total Participation Constraint From One
Side-
• Case-02: For Binary Relationship With Cardinality
Constraint and Total Participation Constraint From Both
Sides-
• If there is a key constraint from both the sides of an entity set
with total participation, then that binary relationship is
represented using only single table.
• Rule-07: For Binary Relationship With Weak Entity Set-
• Weak entity type does not have an independent existence and it
exists only through an identifying relationship with another
entity type called the owner.
• For each weak entity type, create a new relation and include all
of the simple attributes as attributes of the relation. Then
include the primary key of the identifying relation as a foreign
key attribute to this new relation.
• The primary key of the new relation is the combination of the
primary key of the identifying and the partial identifier of the
weak entity type. In this example DEPENDENT is weak
entity.
Thank You
Relational Model
Presented By:-
Dr. Sanjeev Sharma
Relational Model
• The relational model uses a collection of tables to represent
both data and the relationships among those data.
• E.g.
account : information about accounts
depositor : which customer owns which account
customer : information about customers
Integrity Constraints
• These are the rules or constraints applied to the database to
keep data stable, accurate or consistent. To keep database
consistent we have to follow some rules known as integrity
rules or integrity constraints.
– Referential Integrity Rule
– Domain Constraints
– Key Constraints
Referential Integrity Rule
• A foreign key can be either null or it can have only those
values which are present in the primary key with which it is
related.
Presented By:-
Dr. Sanjeev Sharma
Relational Algebra
• The relational algebra is a procedural theoretical language with
operations that work on one or more relations to define another
relation without changing the original relation.
• Thus, both the operands and the results are relations; hence the
output from one operation can become the input to another
operation.
• This allows expressions to be nested in the relational algebra.
This property is called closure. Relational algebra is an
abstract language, which means that the queries formulated in
relational algebra are not intended to be executed on a
computer.
Relational Algebra Operations
• Operations may be unary or binary.
• The functional operations in the relational algebra are :
– Select
– Project
– Union
– Set difference
– Cartesian product
– Rename
– Intersection
– Division
– Join
– Natural Join
Selection Operation
• The selection operation works on a single relation R and
defines a relation that contains only those tuples of R that
satisfy the specified condition (Predicate).
Presented By:-
Dr. Sanjeev Sharma
Basic Set-oriented Operations
• The union operation : The union operation is a binary
operation that is used to find union of relations. Here relations
are considered as sets. So, duplicate values are eliminated. It is
denoted by (∪).
• Conditions for union operation : There are two necessary
conditions for union operation.
– (i) Both the relations have same number of attributes.
– (ii) Data types of their corresponding attributes must be same.
• Two relations are said to be union compatible if they follow
the above two conditions.
• Ex. If you want to find the names of all employees and
names of all students together
• then the query is
πName (Employee) ∪ πName (Student)
Intersection
• Set intersection operation : Set intersection is used to find
common tuples between two relations. It is denoted by (∩).
• If you want to find all the employees from Relation Employee
those are also students. Rules of set union operations are also
applicable here. Then the query, is
πName (Employee) ∩ πName (Student)
Difference
• Set-difference operation : Set-difference operation is a binary
operation which is used to find tuples that are present in one
relation but not in other relation. It is denoted by (—). It
removes the common tuples of two relations and produce a
new relation having rest of the tupels of first relation.
• Ex. If you want the names of those employees that are not
students, then the query, is
πName (Employee) — πName (Student)
• Cartesian product operation : Cartesian product is a binary
operation which is used to combine information of any two
relations. Suppose a relation R1 is having m tuples and other
relation R2 is having n tuples then R1 × R2 has m × n tuples. It
is denoted by (X).
Presented By:-
Dr. Sanjeev Sharma
• There are Three types of outer joins.
• (i) Left outer join : It is used to take all tuples of relation that
are on the left side whether they are matching with tuples of
right side relation or not. It is denoted by ( ).
• Right outer join : It is used to take all tuples of relation
that are on the right side whether they are matching with tuples
of left side relation or not.
• Full outer join : It is used to take all tuples from left and right
relation whether they match with each other or did not match.
Theta (θ) join
• θ in Theta join is the join condition. Theta joins combines
tuples from different relations provided they satisfy the theta
condition.
• R1 ⋈θR2
• Normal form:
– Condition using keys and FDs of a relation to
certify whether a relation schema is in a
particular normal form
Normalization of Relations (2)
• 2NF, 3NF, BCNF
– based on keys and FDs of a relation schema
• 4NF
– based on keys, multi-valued dependencies :
MVDs;
• 5NF
– based on keys, join dependencies : JDs
• Additional properties may be needed to
ensure a good relational design (lossless
join, dependency preservation; see Chapter
15)
Definitions of Keys and Attributes
Participating in Keys (1)
• A superkey of a relation schema R = {A1, A2, ...., An} is a set
of attributes S subset-of R with the property that no two tuples
t1 and t2 in any legal relation state r of R will have t1[S] =
t2[S]