Upload
aziah-nor
View
1.060
Download
0
Tags:
Embed Size (px)
DESCRIPTION
PB204 Database Application Jabatan Perdagangan Politeknik Seberang Perai
Citation preview
PB204
DATABASE APPLICATION
Jabatan PerdaganganPOLITEKNIK SEBERANG PERAI
DATA MODELLING DATA MODELLING
2.0
Entity Relationship Diagram• What is Entity?
“An entity is a business object that represents a group, or category of data.”
Object
Place
Person
Event
Entity Relationship Diagram (cont.)
• Entity Set/TypeSet of entities of the same type that share the same attributes.
STUDENT A STUDENT B STUDENT C STUDENT D
Mr. A Mr.DMr. CMr. B
ENTITY SET : STUDENT
ENTITY SET : TEACHER
Entity Relationship Diagram (cont.)
• What is Relationship? Meaningful association among several entities.
• What is Relationship Type? A set of relationship of the same type.
Entity Relationship Diagram (cont.)
Student A
ENTITY SET : STUDENT
Student B
Student B
Mr A
Mr B
Mr B
ENTITY SET : TEACHER
RELATIONSHIP SET : SUBJECT
Entity Relationship Diagram (cont.)
• What is Attribute?“An attribute is a sub-group of information within an entity.” Descriptive properties possessed by each member of an entity set.
Entity Relationship Diagram (cont.)
• Types of Attributes Single and composite:
• Roll number is an example of single attribute as it can not be divided further.• Name can be divided further into 3 parts consisting of first name , middle name , last name so it is an example of composite attribute.
Single valued and multivalued:•The attributes which have single value are single valued attributes such roll number.•The attributes which has a set of values are called multivalued attributes. Such as any student can have more than 1 telephone number .
Entity Relationship Diagram (cont.)
• Types of Attributes Derived attributes:
• These attributes are derived from the existing attributes of entities.• The value of a derived attribute is not stored , but computed when required.
Descriptive attribute:• The attribute of the relationship is called descriptive attribute.
Entity Relationship Cardinality• It expresses the number of entities to which another entity can be associated via a relationship set.
One to many Many to one One to one Many to many
ONE TO MANY
A B
a1
a4
a2
a3
b4
b3
b2
b1
MANY TO ONE
b2
a1
a2
a5b3
b2
b1
a3
a4
A B
ONE TO ONE
a1
a2
a3
a4 b4
b3
b2
b1
A B
MANY TO MANY
a1
a3
a2
b4
b3
b2
b1
a4
A B
ROLE
• Not specified when entity sets that participate in a relationship set are distinct.
• Clarification is needed only when the entity sets of a relationship set are not distinct.
The function that an entity plays in a relationship is called that entity’s role.
RECURSIVE RELATIONSHIP
When entities are self-linked then such a relationship is called a recursive relationship.
TOTAL PARTICIPATIONThe participation of an entity set E in a relationship set R is said to be TOTAL if every entity in E participates in at
least one relationship in R.
Student A
ENTITY SET : STUDENT
Student B
Student B
Mr A
Mr B
Mr B
ENTITY SET : TEACHER
RELATIONSHIP SET : SUBJECT
PARTIAL PARTICIPATION
Mr A
ENTITY SET : DEPARTMENT
Mr B
Mr B
PB204
P2113
BBC101
ENTITY SET : COURSES
RELATIONSHIP SET : COURSE
The participation an entity set E in a relationship set R is said to be PARTIAL if only some entities in E participate
in relationships in R.
Weak entity set
• Existence of weak entity set depends on the existence of a strong entity set which is called the identifying entity set.
• The relationship is always many-to-one from weak to identifying.
• Participation of the weak entity set in the relationship must be total.
An entity set that does not have sufficient attributes to form a primary key is referred to as a weak entity set.
Types of Keys• A key is a set of columns that can be used to identify or access a particular row or rows • The key is identified in the description of a table, index, or referential constraint• The same column can be part of more than one key• A unique key is a key that is constrained so that no two of its values are equal. • The columns of a unique key cannot contain NULL values. • For example, an employee number column can be defined as a unique key, because each value in the column identifies only one employee. No two employees can have the same employee number.
Types of Keys (cont.)
• Candidate KeyAll available unique, required identifiers of an entity
• Primary KeyA unique, required identifier of an entityThe best one of candidate keys
• Foreign KeyA reference key to another entityThis key is the primary key of another entityA table can have many foreign keys A foreign key is nullable if any part is nullable A foreign key value is null if any part is null
Types of Keys (cont.)
Primary Key
• Natural primary key: A natural primary key is one that exists in the data itself.• Surrogate primary key: The primary key that you have created where non existed
before.• Primary key requires the consideration not just of the
current data, but of possible future data as well.
Types of Keys (cont.)
Why is it important to identify primary key?
• The primary key is the main “Handle” that the database server uses to grab the information in which you are interested.
• By identifying a primary key, you are telling the server which information you want to work with at the moment.
Types of Keys (cont.)
Foreign Key
• A primary key of one table that is included in another table.
• Links the records in one database table to another table.
End Of Chapter 2End Of Chapter 2