Chapter 2


Published on

PB204 Database Application Jabatan Perdagangan Politeknik Seberang Perai

  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Chapter 2

  2. 2. DATA MODELLING 2.0
  3. 3. Entity Relationship Diagram <ul><li>What is Entity? </li></ul><ul><ul><li>“ An entity is a business object that represents a group, or category of data.” </li></ul></ul><ul><li>Object </li></ul><ul><li>Place </li></ul><ul><li>Person </li></ul><ul><li>Event </li></ul>
  4. 4. Entity Relationship Diagram (cont.) <ul><li>Entity Set/Type </li></ul><ul><ul><li>Set of entities of the same type that share the same attributes. </li></ul></ul>STUDENT A STUDENT B STUDENT C STUDENT D Mr. A Mr.D Mr. C Mr. B ENTITY SET : STUDENT ENTITY SET : TEACHER
  5. 5. Entity Relationship Diagram (cont.) <ul><li>What is Relationship? </li></ul><ul><ul><li>Meaningful association among several entities. </li></ul></ul><ul><li>What is Relationship Type? </li></ul><ul><ul><li>A set of relationship of the same type. </li></ul></ul>
  6. 6. 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
  7. 7. Entity Relationship Diagram (cont.) <ul><ul><li>What is Attribute? </li></ul></ul><ul><ul><li>“ An attribute is a sub-group of information within an entity.” </li></ul></ul><ul><ul><li>Descriptive properties possessed by each member of an </li></ul></ul><ul><ul><li>entity set. </li></ul></ul>
  8. 8. Entity Relationship Diagram (cont.) <ul><ul><li>Types of Attributes </li></ul></ul><ul><ul><li>Single and composite: </li></ul></ul><ul><ul><ul><li>Roll number is an example of single attribute as it can not </li></ul></ul></ul><ul><ul><ul><li>be divided further. </li></ul></ul></ul><ul><ul><ul><li>Name can be divided further into 3 parts consisting of first </li></ul></ul></ul><ul><ul><ul><li>name , middle name , last name so it is an example of </li></ul></ul></ul><ul><ul><ul><li>composite attribute. </li></ul></ul></ul><ul><ul><li>Single valued and multivalued: </li></ul></ul><ul><ul><ul><li>The attributes which have single value are single valued attributes such roll number. </li></ul></ul></ul><ul><ul><ul><li>The attributes which has a set of values are called multivalued attributes. Such as any student can have more than 1 telephone number . </li></ul></ul></ul>
  9. 9. Entity Relationship Diagram (cont.) <ul><ul><li>Types of Attributes </li></ul></ul><ul><ul><li>Derived attributes: </li></ul></ul><ul><ul><ul><li>These attributes are derived from the existing attributes of </li></ul></ul></ul><ul><ul><ul><li>entities. </li></ul></ul></ul><ul><ul><ul><li>The value of a derived attribute is not stored , but </li></ul></ul></ul><ul><ul><ul><li>computed when required. </li></ul></ul></ul><ul><ul><li>Descriptive attribute: </li></ul></ul><ul><ul><ul><li>The attribute of the relationship is called descriptive </li></ul></ul></ul><ul><ul><ul><li>attribute. </li></ul></ul></ul>
  10. 10. Entity Relationship Cardinality <ul><li>It expresses the number of entities to which another entity </li></ul><ul><li>can be associated via a relationship set. </li></ul><ul><ul><li>One to many </li></ul></ul><ul><ul><li>Many to one </li></ul></ul><ul><ul><li>One to one </li></ul></ul><ul><ul><li>Many to many </li></ul></ul>
  11. 11. ONE TO MANY A B a1 a4 a2 a3 b4 b3 b2 b1
  12. 12. MANY TO ONE A B b2 a1 a2 a5 b3 b2 b1 a3 a4
  13. 13. ONE TO ONE A B a1 a2 a3 a4 b4 b3 b2 b1
  14. 14. MANY TO MANY A B a1 a3 a2 b4 b3 b2 b1 a4
  15. 15. ROLE <ul><li>Not specified when entity sets that participate in a relationship set are distinct. </li></ul><ul><li>Clarification is needed only when the entity sets of a relationship set are not distinct. </li></ul>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.
  16. 16. TOTAL PARTICIPATION The 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
  17. 17. 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.
  18. 18. Weak entity set <ul><li>Existence of weak entity set depends on the existence of a strong entity set which is called the identifying entity set. </li></ul><ul><li>The relationship is always many-to-one from weak to identifying. </li></ul><ul><li>Participation of the weak entity set in the relationship must be total. </li></ul>An entity set that does not have sufficient attributes to form a primary key is referred to as a weak entity set.
  19. 19. Types of Keys <ul><li>A key is a set of columns that can be used to identify or </li></ul><ul><li>access a particular row or rows </li></ul><ul><li>The key is identified in the description of a table, index, or </li></ul><ul><li>referential constraint </li></ul><ul><li>The same column can be part of more than one key </li></ul><ul><li>A unique key is a key that is constrained so that no two of its </li></ul><ul><li>values are equal. </li></ul><ul><li>The columns of a unique key cannot contain NULL values. </li></ul><ul><li>For example, an employee number column can be defined as </li></ul><ul><li>a unique key, because each value in the column identifies </li></ul><ul><li>only one employee. No two employees can have the same </li></ul><ul><li>employee number. </li></ul>
  20. 20. Types of Keys (cont.) <ul><li>Candidate Key </li></ul><ul><ul><li>All available unique , required identifiers of an entity </li></ul></ul><ul><li>Primary Key </li></ul><ul><ul><li>A unique, required identifier of an entity </li></ul></ul><ul><ul><li>The best one of candidate keys </li></ul></ul><ul><li>Foreign Key </li></ul><ul><ul><li>A reference key to another entity </li></ul></ul><ul><ul><li>This key is the primary key of another entity </li></ul></ul><ul><ul><li>A table can have many foreign keys </li></ul></ul><ul><ul><li>A foreign key is nullable if any part is nullable </li></ul></ul><ul><ul><li>A foreign key value is null if any part is null </li></ul></ul>
  21. 21. Types of Keys (cont.) <ul><li>Natural primary key: </li></ul><ul><li>A natural primary key is one that exists in the data itself. </li></ul><ul><li>Surrogate primary key: </li></ul><ul><li>The primary key that you have created where non existed before. </li></ul><ul><li>Primary key requires the consideration not just of the current data, but of possible future data as well. </li></ul>Primary Key
  22. 22. Types of Keys (cont.) <ul><li>The primary key is the main “Handle” that the database server uses to grab the information in which you are interested. </li></ul><ul><li>By identifying a primary key, you are telling the server which information you want to work with at the moment. </li></ul>Why is it important to identify primary key?
  23. 23. Types of Keys (cont.) <ul><li>A primary key of one table that is included in another table. </li></ul><ul><li>Links the records in one database table to another table. </li></ul>Foreign Key
  24. 24. End Of Chapter 2