24
PB204 DATABASE APPLICATION Jabatan Perdagangan POLITEKNIK SEBERANG PERAI

Chapter 2

Embed Size (px)

DESCRIPTION

PB204 Database Application Jabatan Perdagangan Politeknik Seberang Perai

Citation preview

Page 1: Chapter 2

PB204

DATABASE APPLICATION

Jabatan PerdaganganPOLITEKNIK SEBERANG PERAI

Page 2: Chapter 2

DATA MODELLING DATA MODELLING

2.0

Page 3: Chapter 2

Entity Relationship Diagram• What is Entity?

“An entity is a business object that represents a group, or category of data.”

Object

Place

Person

Event

Page 4: Chapter 2

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

Page 5: Chapter 2

Entity Relationship Diagram (cont.)

• What is Relationship? Meaningful association among several entities.

• What is Relationship Type? A set of relationship of the same type.

Page 6: Chapter 2

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

Page 7: Chapter 2

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.

Page 8: Chapter 2

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 .

Page 9: Chapter 2

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.

Page 10: Chapter 2

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

Page 11: Chapter 2

ONE TO MANY

A B

a1

a4

a2

a3

b4

b3

b2

b1

Page 12: Chapter 2

MANY TO ONE

b2

a1

a2

a5b3

b2

b1

a3

a4

A B

Page 13: Chapter 2

ONE TO ONE

a1

a2

a3

a4 b4

b3

b2

b1

A B

Page 14: Chapter 2

MANY TO MANY

a1

a3

a2

b4

b3

b2

b1

a4

A B

Page 15: Chapter 2

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.

Page 16: Chapter 2

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

Page 17: Chapter 2

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.

Page 18: Chapter 2

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.

Page 19: Chapter 2

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.

Page 20: Chapter 2

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

Page 21: Chapter 2

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.

Page 22: Chapter 2

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.

Page 23: Chapter 2

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.

Page 24: Chapter 2

End Of Chapter 2End Of Chapter 2