Presentation on theme: "More Diagramming & Practice with Relationship Modeling"— Presentation transcript:
1 More Diagramming & Practice with Relationship Modeling
2 ER NotationThere is no standard for representing data objects in ER diagrams. Each modeling methodology uses its own notation. The original notation used by Chen is widely used in academics texts and journals but rarely seen in either CASE tools or publications by non-academics. Today, there are a number of notations used, among the more common are Bachman, crow's foot, and IDEFIX.All notational styles represent entities as rectangular boxes and relationships as lines connecting boxes. Each style uses a special set of symbols to represent the cardinality of a connection. The symbols used for the basic ER constructs are:Entities are represented by labeled rectangles. The label is the name of the entity. Entity names should be singular nouns.Relationships are represented by a solid line connecting two entities. The name of the relationship is written above the line. Relationship names should be verbs.Attributes, when included, are listed inside the entity rectangle. Attributes which are identifiers are underlined. Attribute names should be singular nouns.Cardinality of many is represented by a line ending in a crow's foot. If the crow's foot is omitted, the cardinality is one.Existence is represented by placing a circle or a perpendicular bar on the line. Mandatory existence is shown by the bar (looks like a 1) next to the entity for an instance is required. Optional existence is shown by placing a circle next to the entity that is optional.
3 Steps In Building the Data Model While ER model lists and defines the constructs required to build a data model, there is no standard process for doing so. Typically, the entities and relationships are modeled first, followed by key attributes, and then the model is finished by adding non-key attributes. The sequence used for this course are:Identification of data objects and relationshipsDrafting the initial ER diagram with entities and relationshipsRefining the ER diagramAdd key attributes to the diagramAdding non-key attributesValidating the model through normalizationAdding integrity rules to the Model
4 Single Entity Data Model CUSTOMERNameAddressCityStateZip CodeTelephone*Account Number
7 Many-to-Many Relationship (m:m) To depict the m:m relationship, a third entity is created forming two 1:m relationshipsThis entity is known as an intersection entity or the junction tableThe vertical bar added to the “chicken foot” indicates the unique identifier is concatenated from ORDER and PRODUCT
8 Many-to-Many Relationship (m:m) An order has many requested items, but each requested item refers to only one orderA product can be requested many times, but each requested item refers to only one productCUSTOMERNameAddressCityStateZip CodeTelephone*Account NumberORDER*OrderNumberOrderDatePromiseDatePRODUCT*ProductNoDescriptionUnitPriceRoomFinishQtyOnHandREQUESTQtyOrderedLinePrice
10 Many-to-Many Relationship (m:m) Foreign keyForeign keysTogether they make up the primary key for this tableRemember the primary keys and foreign keys must be the same data type and length
11 The final part of the ERDiagram The final part of the ERDiagram is the series of notations at the end of the lines. It is their appearance that gives rise to the name "Crow's Foot," which is what this kind of ERD is called. These lines indicate the nature of the relationship, which is called cardinality.
13 Applying these interpretations In the relationship between Employee and Department, one or more employees belong to one department. In other words, each employee belongs to one and only one department, but each department has at least one and probably several employees in it. This is called a one-to-many relationship.In the relationship between Employee and Class we see that zero or more employees can take zero or more classes. In other words, a class could be taken by no one or by several employees. Similarly an employee could take zero classes or several classes. This is called a many-to-many relationship.
14 Applying these interpretations The relationships between Employee and Salaried Employee and between Employee and Hourly Employee are both one-to-one relationships. Each person in the Salaried Employee entity will have a corresponding record in the Employee entity. Also, each person in the Hourly Employee entity will have a corresponding record in the Employee entity. Since an employee will not be both hourly and salary, it is obvious that the Salaried Employee and Hourly Employee entities will each have fewer records than the Employee entity. For instance, there might be 1,000 employees, 700 of whom are hourly and 300 of whom are salaried. So when you see entities in a one-to-one relationship, it doesn't necessarily mean that they have the same number of records. It simply means that each record in the one entity has no more than one corresponding record in the other entity.
15 Try this:Scenario:Our database has authors who have an authorid, firstname, and lastname. These authors have many books, and the books have many authors. The books have a bookid, and a booktitle.Create the data model and show the relationships between the tables.
17 Try this:Scenario:Languages spoken, an important (and likely a multivalued) attribute for a job candidate, deserves elevation to entity status in this database. The original creator of this customer's database had realized this and created a separate table for languages. The problem then became that, if each candidate can speak many languages and each language can be spoken by many candidates, there is a many-to-many relationship between the two tables.In the candidates entity we have a candidateid, salutation, fname, lname, address, and city.In the languages entity we have a languageCreate the data model and show the relationships between the tables.
19 Try This:This database must track the members’ orders for merchandise. The info for each order must include the member who placed the order, amount paid, form of payment, order date, status of order, shipped date, products sold, and the quantity of each product.
20 Try This:This database must store information about the staff who work for the organization. The information must include the first names, last names, and middle initials, as well as the staff members’ addresses, phone numbers, and start dates. The information must also include their positions within the organization as well as who each one’s supervisor is.
21 Creating the relationships in Visio or MySQL Workbench In Visio or MySQL Workbench, it is only a drawing to depict how your relationship will look once you get it into mySQL. It does not have an physical impact on the data itself.Note: some of the newer programs allow you to directly import your data from their drawing program.
22 Steps In Building the Data Model While ER model lists and defines the constructs required to build a data model, there is no standard process for doing so. Typically, the entities and relationships are modeled first, followed by key attributes, and then the model is finished by adding non-key attributes. The sequence used for this course are:Identification of data objects and relationshipsDrafting the initial ER diagram with entities and relationshipsRefining the ER diagramAdd key attributes to the diagramAdding non-key attributesValidating the model through normalizationAdding integrity rules to the Model