Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
146 views

Lecture Note 2 - Entity Relationship Diagram

The document discusses key concepts in entity-relationship diagrams including entities, attributes, relationships, keys, and constraints. Entities represent real-world objects with identifying attributes. Relationships define associations between entities and have cardinality defining the number of entities that can be linked. Primary keys uniquely identify entities, foreign keys link entities, and composite keys are combinations of attributes forming unique identifiers. Examples are provided to illustrate one-to-one, one-to-many, and many-to-many relationships. Finally, the document shows how to represent these concepts in an entity-relationship diagram.

Uploaded by

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

Lecture Note 2 - Entity Relationship Diagram

The document discusses key concepts in entity-relationship diagrams including entities, attributes, relationships, keys, and constraints. Entities represent real-world objects with identifying attributes. Relationships define associations between entities and have cardinality defining the number of entities that can be linked. Primary keys uniquely identify entities, foreign keys link entities, and composite keys are combinations of attributes forming unique identifiers. Examples are provided to illustrate one-to-one, one-to-many, and many-to-many relationships. Finally, the document shows how to represent these concepts in an entity-relationship diagram.

Uploaded by

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

Database and Data structures I

Unit 2
Entity Relationship
Diagram

Dilini Thamarasee 1
What we discuss Today………

• Entities

• Attributes

• Constraints

• Key Constraints

• Relationships
Entity –Relationship Model Concepts

• Entities are specific objects or things in the mini-world that are


represented in the database

Ex :- A company

A job

A university

• Represent using a Rectangle in ER Diagram


What Should an Entity Be?
• SHOULD BE:

– An object that will have many instances in the database

– An object that will be composed of multiple attributes

– An object that we are trying to model

• SHOULD NOT BE:

– A user of the database system

– An output of the database system (e.g., a report)


Types of Entities
• Strong Entity

– An entity that has existence independence

– Can stand alone whether another entity exists or not

• Weak Entity

– Does not have a key attribute

– Depends in Strong Entity(Without Strong Entity, Weak Entity can not exist)

– Identified by the combination of:

A partial key of the weak entity type


5
The particular entity they are related to in the identifying entity type
Entity
• A real-world object, either animate or inanimate, that can be easily identifiable.

Example : School Database


• Teachers

• Students

• Classes

• Courses offered

• Entity set

– Collection of similar types of entities.

– Contains entities with attribute sharing similar values.


Attributes

• Entities are represented by means of their properties, called attributes.

• All attributes have values.

Example : Student :- Name, Class, Age


Types of Attributes

• Simple

– Each entity has a single atomic value for the attribute.


• example:- ID Number, Sex

• Composite

– The attribute may be composed of several components.


• Address (Apt#, House#, Street, City, State, ZipCode, Country)
• Name (FirstName, MiddleName, LastName).
Types of Attributes
Multi Valued

• An entity may have multiple values for that attribute

Color of a CAR

Previous Degrees of a STUDENT.


Stored Versus Derived Attributes
• In some cases two (or more) attribute values are related

• The value of Age can be determined from the current (today’s) date and the value of
that person’s Birthdate.

• The Age attribute is hence called a derived attribute

• And is said to be derivable from the Birthdate attribute, which is called a stored
attribute
Null and Complex Attributes

Complex Attributes
Null Values Combination of composite and multi-valued
Some particular entity may not have an applicable
attributes
value for an attribute
Previous Degrees of a STUDENT is a
Ex : The Apartment Number
composite multi-valued attribute

{PreviousDegrees (College, Year, Degree,


Field)}.
Relationship

• The association among entities is called relationship.

– Ex: Employee works_at department

– Ex: Student enrolls in a course

• Relationship Set

– A set of relationships of similar type is called a relationship set.

– Like entities, a relationship too can have attributes.

– These attributes are called descriptive attributes.


Types of Relationships(Mapping Cardinality)
• Number of entities in one entity set, which can be associated with the number of
entities of other set via relationship set.

• One to one

• One to many

• Many to many

– Cardinality is the number of instance of an entity from a relation that can be


associated with the relation.
One to One
 When each entity in each entity set can take part only once in the relationship, the
cardinality is one to one.
One to One

 Assume that a male can marry to one female and a female can marry to one male.

 So the relationship will be one to one.


One to Many
• When entities in one entity set can take part only once in the relationship set and
entities in other entity set can take part more than once in the relationship set

• cardinality is many to one


One to Many
• Assume that a customer can have many accounts, but one account having one customer.

• So the cardinality will be one to many.

• It means that for one customer there can have n accounts but for one account, there will
be only one customer.
Many to Many

• When entities in all entity sets can take part more than once in the relationship

• cardinality is many to many.


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.


Degree of a Relationship

• Number of entities participate with the relationship

– If only one entity connect with the relationship – Unary (degree 1)

– If two entities connect with the relationship – Binary (degree 2)

– If three entities connect with the relationship – Ternary (degree 3)

– If n number of entities connect with the relationship – N ary (Degree n)


Participation Constraints
• Total Participation – All the instance of one entity is participate with the
relation

• Partial Participation – Some entities of one entity is participate with the


relation
Types of keys (key Constraints)

• Primary Key

• Candidate Key

• Composite Key

• Foreign Key
Primary Key

• The Key which is used to uniquely identify the data/records in the table

Example – Student Table


Student ID is a Primary Key

Same Student ID doesn’t have for more than one student


Candidate Key

• Set of keys that is minimal and can uniquely identify any data row in the
table.

Composite Key

• If any single attribute of a table is not capable of being the key


•It cannot identify a row uniquely, then we combine two or more attributes to
form a key. This is known as a composite key.
Foreign Key

• A foreign key is an attribute value in a table that acts as the primary key in
another table.

• The foreign key is useful in linking together two tables


Example – Identify the Keys
Example – Identify the Keys
Student Subject
Stu_No Name Mobile Sub_No Sub_No Sub_Name Sub_Lecturer
1 Amal 0110990912 10 10 DBMS Dilini

2 Achini 0812245671 20 20 Web Valuka

30 Maths Sandamini
3 Naduni 0412345654 10

Enroll
Stu_No Sub_No

1 10

2 20

3 10
Summary of ER Diagram Notations
Example

• Draw a ERD about Bank data

• Assumptions

• A Bank has many branches

• A customer can have many accounts in a branch

• A branch is holding many accounts

• A branch offering loans

• Customer can get many loans from a branch


Answer
31

You might also like