Dbms Unit-2 Presentation.pptx
Dbms Unit-2 Presentation.pptx
1
Unit 3- Relational Database Design
• Relational Model:
– Basic concepts,
– Attributes and Domains,
– CODD's Rules
2
Relational model
3
Relational model
4
Relational model - Terminologies
5
Relational model - Terminologies
6
Relational model - Terminologies
Relation Table
Tuple Row, Record
Attribute Column, Field
Domain It consists of set of legal
values
Cardinality It consists of number of rows
Degree It contains number of columns
7
Relational model - Operations
8
Relational model – Codd rules
9
Relational model – Codd rules
10
Relational model – Codd rules
12
Database Design and ER Model
13
Department of AIML ZCOER, Pune
Database Design and ER Model
14
Department of AIML ZCOER, Pune
Database Design and ER Model
15
Department of AIML ZCOER, Pune
Database Design and ER Model
16
Department of AIML ZCOER, Pune
Database Design and ER Model
• Components of ER Diagram
• You base an ER Diagram on three basic concepts:
• Entities
– Weak Entity
• Attributes
– Key Attribute
– Composite Attribute
– Multivalued Attribute
– Derived Attribute
• Relationships
– One-to-One Relationships
– One-to-Many Relationships
– Many-to-One Relationships
– Many-to-Many Relationships
17
Department of AIML ZCOER, Pune
Symbols used in ER Diagram
18
Department of AIML ZCOER, Pune
ER Diagram
Entity
An Entity may be an object with a physical existence – a particular person,
car, house, or employee – or it may be an object with a conceptual
existence – a company, a job, or a university course.
Entity are of two types
1.Tangible Entity – Which can be touched like car , person etc.
2.Non – tangible Entity – Which can’t be touched like air , bank account etc.
Entity Set: An Entity is an object of Entity Type and a set of all entities is
called an entity set. For Example, E1 is an entity having Entity Type Student
and the set of all students is called Entity Set.
In ER diagram, Entity Type is represented as:
19
Department of AIML ZCOER, Pune
ER Diagram
20
Department of AIML ZCOER, Pune
ER Diagram
1. Strong Entity
A Strong Entity is a type of entity that has a key Attribute. Strong
Entity does not depend on other Entity in the Schema. It has a primary
key, that helps in identifying it uniquely, and it is represented by a
rectangle. These are called Strong Entity Types.
2. Weak Entity
An Entity type has a key attribute that uniquely identifies each entity
in the entity set. But some entity type exists for which key attributes
can’t be defined. These are called Weak Entity types.
21
Department of AIML ZCOER, Pune
ER Diagram
Attributes
Attributes are the properties that define the entity type. For example,
Roll_No, Name, DOB, Age, Address, and Mobile_No are the attributes that
define entity type Student. In ER diagram, the attribute is represented by
an oval.
1. Key Attribute
The attribute which uniquely identifies each entity in the entity set is called
the key attribute. For example, Roll_No will be unique for each student. In
ER diagram, the key attribute is represented by an oval with underlying
lines.
22
Department of AIML ZCOER, Pune
ER Diagram
2. Composite Attribute
An attribute composed of many other attributes is called a composite
attribute.
For example, the Address attribute of the student Entity type consists of
Street, City, State, and Country.
In ER diagram, the composite attribute is represented by an oval
comprising of ovals.
23
Department of AIML ZCOER, Pune
ER Diagram
3. Multivalued Attribute
An attribute consisting of more than one value for a given entity. For example,
Phone_No (can be more than one for a given student). In ER diagram, a
multivalued attribute is represented by a double oval.
4. Derived Attribute
An attribute that can be derived from other attributes of the entity type is known
as a derived attribute. e.g.; Age (can be derived from DOB). In ER diagram, the
derived attribute is represented by a dashed oval.
24
Department of AIML ZCOER, Pune
ER Diagram
The Complete Entity Type Student with its Attributes can be represented as:
25
Department of AIML ZCOER, Pune
ER Diagram
26
Department of AIML ZCOER, Pune
ER Diagram
27
Department of AIML ZCOER, Pune
ER Diagram
The number of different entity sets participating in a relationship set is called
the degree of a relationship set.
3. Ternary Relationship: When there are n entities set participating in a relation,
the relationship is called an n-ary relationship.
Cardinality
The number of times an entity of an entity set participates in a relationship set is
known as cardinality. Cardinality can be of different types:
1. One-to-One: When each entity in each entity set can take part only once in the
relationship, the cardinality is one-to-one. Let us assume that a male can marry
one female and a female can marry one male. So the relationship will be
one-to-one.
28
Department of AIML ZCOER, Pune
ER Diagram
Using Sets, it can be represented as:
29
Department of AIML ZCOER, Pune
ER Diagram
3. Many-to-One: When entities in one entity set can take part only
once in the relationship set and entities in other entity sets can take part
more than once in the relationship set, cardinality is many to one. Let us
assume that a student can take only one course but one course can be
taken by many students. So the cardinality will be n to 1. It means that
for one course there can be n students but for one student, there will be
only one course.
30
Department of AIML ZCOER, Pune
ER Diagram
4. Many-to-Many: When entities in all entity sets can take part more than
once in the relationship cardinality is many to many. Let us assume that a
student can take more than one course and one course can be taken by
many students. So the relationship will be many to many.
31
Department of AIML ZCOER, Pune
ER Diagram
Participation Constraint
Participation Constraint is applied to the entity participating in the
relationship set.
1. Total Participation – Each entity in the entity set must participate in the
relationship. If each student must enroll in a course, the participation of
students will be total. Total participation is shown by a double line in the
ER diagram.
2. Partial Participation – The entity in the entity set may or may NOT
participate in the relationship. If some courses are not enrolled by any of
the students, the participation in the course will be partial.
The diagram depicts the ‘Enrolled in’ relationship set with Student Entity
set having total participation and Course Entity set having partial
participation.
32
Department of AIML ZCOER, Pune
ER Diagram
Every student in the Student Entity set participates in a relationship but there exists a
course C4 that is not taking part in the relationship.
33
Department of AIML ZCOER, Pune
ER Diagram - Cardinality
34
Department of AIML ZCOER, Pune
ER Diagram
35
Department of AIML ZCOER, Pune
ER Diagram
36
Department of AIML ZCOER, Pune
ER Diagram
37
Department of AIML ZCOER, Pune
Keys
• In databases, keys are fundamental in maintaining data integrity and
organization.
• They serve as unique identifiers and establish relationships between
tables, enabling efficient data retrieval and manipulation.
• With the help of keys, users can relate tables.
38
Department of AIML ZCOER, Pune
Keys
Primary key
• An entity can contain multiple keys, The key which is most suitable from those
lists becomes a primary key.
• In the EMPLOYEE table, ID can be the primary key since it is unique for each
employee. We can even select License_Number and Passport_Number as primary
keys since they are also unique.
• For each entity, the primary key selection is based on requirements and
developers.
•
39
Department of AIML ZCOER, Pune
Keys
2. Candidate key
A candidate key is an attribute or set of attributes that can uniquely identify a
tuple.
Except for the primary key, the remaining attributes are considered a candidate key.
The candidate keys are as strong as the primary key.
For example: In the EMPLOYEE table, id is best suited for the primary key. The rest
of the attributes, like SSN, Passport_Number, License_Number, etc., are considered a
candidate key.
40
Department of AIML ZCOER, Pune
Keys
3. Super key
Super keys are collections of one or more properties (columns) in database
management systems that allow a tuple (row) in a relation (table) to be distinctly
identified.
order_id customer_id product_id quantity
1 101 1 2
2 102 2 1
3 101 3 3
4 103 1 1
5 102 4 2
42
Department of AIML ZCOER, Pune
Keys
5. Alternate key
• There may be one or more attributes or a combination of attributes that uniquely identify
each tuple in a relation.
• These attributes or combinations of the attributes are called the candidate keys.
• One key is chosen as the primary key from these candidate keys, and the remaining
candidate key, if it exists, is termed the alternate key.
• In other words, the total number of the alternate keys is the total number of candidate keys minus
the primary key.
• The alternate key may or may not exist. If there is only one candidate key in a relation, it
does not have an alternate key.
• For example, employee relation has two attributes, Employee_Id and PAN_No, that act
as candidate keys. In this relation, Employee_Id is chosen as the primary key, so the other
candidate key, PAN_No, acts as the Alternate key.
43
Department of AIML ZCOER, Pune
Keys
5. Alternate key
44
Department of AIML ZCOER, Pune
Keys
5. Composite key
• Whenever a primary key consists of more than one attribute, it is known as a
composite key. This key is also known as Concatenated Key.
45
Department of AIML ZCOER, Pune
Keys
7. Artificial key
• The key created using arbitrarily assigned data are known as artificial keys.
• These keys are created when a primary key is large and complex and has no
relationship with many other relations.
• The data values of the artificial keys are usually numbered in a serial order.
• The primary key, which is composed of Emp_ID, Emp_role, and Proj_ID, is large
in employee relations.
• So it would be better to add a new virtual attribute to identify each tuple in the
relation uniquely.
46
Department of AIML ZCOER, Pune
Converting ER diagram into tables
47
Converting ER diagram into tables
1. Book Book (Book_id, Title, Author, Price, Available)
Table
Column Name Data Type Constraints
Book_id INT PRIMARY KEY
Title VARCHAR NOT NULL
Author VARCHAR NOT NULL
Price DECIMAL NOT NULL
Available BOOLEAN NOT NULL
48
Converting ER diagram into tables
3. Member
Table
Column Name Data Type Constraints Member (Member_id, Name, Address,
Member_date, Member_type,
Member_id INT PRIMARY KEY
Expiry_date)
Name VARCHAR NOT NULL
Address VARCHAR NOT NULL
Member_date DATE NOT NULL
Member_type VARCHAR NOT NULL
Expiry_date DATE NOT NULL
49
Converting ER diagram into tables
5. Borrowed_by Table (Relationship between Book and Member)
50
Integrity Constraints
• 1. Domain constraints
• Domain constraints can be
defined as the definition of a
valid set of values for an
attribute.
• The data type of domain
includes string, character,
integer, time, date, currency,
etc.
• The value of the attribute
must be available in the
corresponding domain.
Integrity Constraints
2/17/2025 drdytdtudutftuftftftfytfytfty 59
Schema Diagram
It helps to understand:
60
Schema Diagram
Entities: These are the objects or concepts about which data is stored.
Entities are typically represented as rectangles.
Relationships: These show how two or more entities interact with each other.
Relationships are illustrated by a line connecting the related entities.
62