1 / 23

Chapter 2

Chapter 2. Entity relationship model. Concept. Entity set Attribute Relationship Set Entity-Relationship Diagram. Entity Sets. A database can be modeled as: a collection of entities, relationship among entities.

falala
Download Presentation

Chapter 2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 2 Entity relationship model

  2. Concept • Entity set • Attribute • Relationship Set • Entity-Relationship Diagram

  3. Entity Sets • A database can be modeled as: • a collection of entities, • relationship among entities. • An entity is an object that exists and is distinguishable from other objects. • Example: specific person, company, event, plant • Entities have attributes • Example: people have names and addresses • An entity set is a set of entities of the same type that share the same properties. • Example: set of all persons, companies, trees, holidays

  4. Entity Sets customer-id customer- customer- customer- loan- amount name street city number

  5. Weak Entity Sets • An entity set that does not have a primary key is referred to as a weak entity set. • The existence of a weak entity set depends on the existence of a identifying entityset • The discriminator (or partial key) of a weak entity set is the set of attributes that distinguishes among all the entities of a weak entity set. • The primary key of a weak entity set is formed by the primary key of the strong entity set on which the weak entity set is existence dependent, plus the weak entity set’s discriminator.

  6. Examples • In a university, a course is a strong entity and a course-offering can be modeled as a weak entity • The discriminator of course-offering would be semester (including year) and section-number (if there is more than one section) • If we model course-offering as a strong entity we would model course-number as an attribute. Then the relationship with course would be implicit in the course-number attribute

  7. Attributes • The information about one entity is expressed by a set of (attribute,value) pairs: • customer = (customer-id, customer-name, customer-street, customer-city) loan = (loan-number, amount) • Values of attributes belong to different value-sets or domains, for example, • Amout is an integer between 1 and 12000 • Each entity has a value for each of its attributes.For each attribute ,there is a set of permitted values called domain or value set.

  8. Relationship Set • A relationship is an association among several entities • A relationship set is a subset of the cartesian product of entity sets. • Example:R-set:” Person HAS_EATEN Dish IN Place “ |----------------------------------------------------------| | RSet 'Person HAS_EATEN Dish IN Place‘ | |----------------------------------------------------------| | Person | Dish| Place | |------------------|------------------|--------------------| | Steve | Duck | Kuala Lumpur | | Weiren | Duck | Beijing | | Paolo | Noodles| Naples | | Mike | Fondue | Geneva | | Paolo | Duck | Beijing | |----------------------------------------------------------|

  9. Relationship Set(cont) • An attribute can also be property of a relationship set. • For instance, the depositor relationship set between entity sets customer and account may have the attribute access-date

  10. Mapping Cardinalities • Express the number of entities to which another entity can be associated via a relationship set. • Most useful in describing binary relationship sets. • For a binary relationship set the mapping cardinality must be one of the following types: • One to one • One to many • Many to one • Many to many

  11. Mapping Cardinalities • One to one: An entity in A is associated with at most one entity in B, & an entity in B is associated with at most one entity in A. • One to many: An entity in A is associated with any number(zero or more) of entities in B.An entity in B however can be associated with at most one entity in A. • Many to one: An entity in A is associated with at most one entity in B.An entity in B however can be associated with any number(zero or more) of entities in A. • Many to many: An entity in A is associated with any number(zero or more) of entities in B & an entity in B is associated with any number(zero or more) of entities in A.

  12. Rectangles represent entity sets. Diamonds represent relationship sets. Lines link attributes to entity sets and entity sets to relationship sets. Ellipses represent attributes Double ellipses represent multivalued attributes. Dashed ellipses denote derived attributes. Underline indicates primary key attributes (will study later) ER-Diagram

  13. ER-Diagram

  14. Cardinality Constraints • We express cardinality constraints bydrawing either a directed line (), signifying “one,” or an undirected line (—), signifying “many,” between the relationship set and the entity set.

  15. One to many relationship

  16. Many to one relationship

  17. One to one relationship

  18. Roles • Entity sets of a relationship need not be distinct • The labels “manager” and “worker” are called roles; they specify how employee entities interact via the works-for relationship set. • Roles are indicated in E-R diagrams by labeling the lines that connect diamonds to rectangles. • Role labels are optional, and are used to clarify semantics of the relationship

  19. Keys • A super key of an entity set is a set of one or more attributes whose values uniquely determine each entity. • A candidate key of an entity set is a minimal super key • Customer-id is candidate key of customer • account-number is candidate key of account • Although several candidate keys may exist, one of the candidate keys is selected to be the primary key.

  20. Keys

  21. AN ENTITY RELATIONSHIP DIAGRAM METHODOLOGY • Identify Entities • Find Relationships • Draw Rough ERD • Fill in Cardinality • Define Primary Keys • Draw Key-Based ERD • Identify Attributes • Map Attributes • Draw fully attributed ERD • Check Results

  22. Exercise • CSDL đề án công ty theo dõi các thông tin liên quan đến nhân viên, phòng ban và đề án • Cty có nhiều phòng ban, mỗi phòng ban có tên duy nhất, mã phòng duy nhất, một trưởng phòng và ngày nhận chức. Mỗi phòng ban có thể ở nhiều địa điểm khác nhau. • Đề án có tên duy nhất, mã duy nhất, do 1 một phòng ban chủ trì và được triển khai ở 1 địa điểm. • Nhân viên có mã số, tên, địa chỉ, ngày sinh, phái và lương. Mỗi nhân viên làm việc ở 1 phòng ban, tham gia vào các đề án với số giờ làm việc khác nhau. Mỗi nhân viên đều có một người quản lý trực tiếp. • Một nhân viên có thể có nhiều thân nhân. Mỗi thân nhân có tên, phái, ngày sinh và mối quan hệ với nhân viên đó.

  23. HONV NGSINH MANV TENNV MAPHG PHONGBAN PHAI La_truong_phong Phu_trach Phan_cong Lam_viec LUONG MADA TENDA TENPB DCHI DDIEM_DA Exercise NHANVIEN DEAN

More Related