Guidelines for ER to Relational Mapping.
Mapping rules/ guidelines for mapping various ER constructs to Relational model with appropriate examples
Relational Query Languages Formal Query Languages
Introduction to Relational Algebra
Relational operators
Set operators
Join operators
Aggregate functions.
Grouping operator
Relational Calculus concepts
Relational algebra queries for data retrieval with sample relational schemas. relational algebra operations.
2. Session objective
Quick look of previous Session
Database Design Process
ER Modeling concepts
EER Concepts and notations
3. Textbook Reference Book(s) & other resources
T1 Ramez Elmasri & Shamkant B. Navathe, Fundamentals of
Database Systems, Pearson Education, 5th Edition, 2007
Reference Book(s) & other resources
R1 Abraham Silberschatz, Henry F Korth and S Sudarshan,
Database System Concepts, McGraw Hill, 6th Ed., 2013
Text Book
5. Data Definition Language (DDL) allows the DBA or user
to describe and name entities, attributes, and relationships
required for the application plus any associated integrity
and security constraints
Data Manipulation Language (DML) provides basic data
manipulation operations on data held in the database
Data Control Language (DCL) defines activities that are
not in the categories of those for the DDL and DML, such
as granting privileges to users, and defining when proposed
changes to a databases should be irrevocably made
Database Languages
7. DATA Association(ER Model)
Entity:
• A thing or object in real world that is distinguishable from other
objects
Eg: Employee in an organization
• An entity has set of properties and values for he same set of
properties that many uniquely identify an entity
Eg: Employee (EmpIdNo,Mobile no etc)
• An entity set is a set of entities of the same type that share their
same properties or attributes
Eg. Bank (employee(empid),customer(acc number))
8. DATA Association(ER Model)
Entity:
• A thing or object in real world that is distinguishable from other
objects
Eg: Employee in an organization
• An entity has set of properties and values for he same set of
properties that many uniquely identify an entity
Eg: Employee (EmpIdNo,Mobile no etc)
• An entity set is a set of entities of the same type that share their
same properties or attributes
Eg. Bank (employee(empid),customer(acc number))
9. DATA Association(ER Model)
Attributes:
• Descriptive properties possessed by each member of an entity set.
• For each attribute ,there is a set of permitted values called domain
• Student(entity)
• Attributes(std_id,std_nme,std_add,std_class)
10. DATA Association(ER Model)
Attributes
Simple/Composite Sinlge/Muti valued
Derived
Simple :are not
divided in sub parts
eg: unique-id(123456
canot be divided into
12 and 345)
Composite: can be
divided into subparts
Eg: name (first and
last,middle)
single :single value
Eg: order-id
Multi: multiple
values
Eg: multiple phone
numbers
Derived :derived
from otger related
attributes
Eg: age (from name
and DOB)
Age=current_date-DOB
12. Strong and weak entity set
Strong entity Weak entity
Has a primary key Does not have sufficient attributes to form
primary key
Primary key Primary key???
Entity=set payment :
Attribute:
1. Payment_Number
2. Payment_Date
3. Payment_Amount
Eg. EMI to pay for number of users
13. How to form PK from weak entity set
How to from the primary key of a weak
entity set ?
You have to use PK of SE on which weak
entity is dependant plus the WE set
discriminator.
Eg. Same loan pay banking domain table
design and relation to be shown
PK,FK,discriminator
14. Relationship Sets
Relationship Sets-
• A relationship is an association among entities.
• Relationship set is a set of relationship of the
same type.
Eg.
Customer =c1,c2,c3,…..cn
Loan= L1,L2,L3……Ln respectively
Connectivity / Cardinality/Relationships
• It describes the mapping of associated instances
in the relationships
OR
• It expresses the number of entities to which an
entity can be associated via a relationship set
15. Mapping cardinalities
One to one One to many Many to one Many to Many
• One to one:Department and head(company,university)
• One to many :Hod(1,2,3) faculty(1,2,3)single hod can represent
many faculty likewise one team leader represent many emp
• Many to one:relation of course to faculty many courses are being
taught by one faculty .
• Many to many : projrct 1 to n emp 1 to n
OR
• It expresses the number of entities to which an entity can be
associated via a relationship set
Mapping(Connectivity / Cardinality/Relationships)
18. How an entity participate in a relationship???
Total: If every entity in E participates in t=atleast one
relationship in R
Eg. Student elective subjects at least register for a course.
Partial: Some entities in E participates in in
relationship R
Eg. Student and CR relation( not all the students are
participated for being CR)
Participation constraint
19. A key allows to identify a set of attributes to
distinguish entities from each other.
Types of key:
Superkey: Set of one or more attributes that allows
to identify an entity uniquely.(It may contain extra
attributes)eg. {Std_Id,Std_Name}
Candidate key: It is minimal set of super key which
can uniquely identify an entity. eg. {Std_Id} not id
and name both.
New definition: SK for which no subset is a superkey.
Key in Relation
20. Key in Relation
Note : More than one CK is possible in relation
Suppose we have 5 CK
Primary key: vvimp
Chosen by DBA very important to identify the entity and the record. Eg.???
Alternate Key/s:
CK-PK=AK ,5-1=4 . All 4 can become PK but not chosen by DBA.
Secondary Key:
Used for data retrieval. Eg.Emp_id(PK) ,Dept(Secondary key)
I want to find the employee wrt to dept then Dept is secondary key.
Many time in a Group by clause we use Secondary key.
Foreign Key: PK of one related to another entity id FK
Composite Key: Combination of two or more columns in a table that
uniquely identify the tuple/record/row.
Eg.CutomerId,OrderID,SalesDetail