Presentation is loading. Please wait.

Presentation is loading. Please wait.

Entity Relationship Diagrams and Relational DBs BSAD 141 Dave Novak.

Similar presentations


Presentation on theme: "Entity Relationship Diagrams and Relational DBs BSAD 141 Dave Novak."— Presentation transcript:

1 Entity Relationship Diagrams and Relational DBs BSAD 141 Dave Novak

2 Topics Covered ERD (entity relationship diagram) Data Modeling Entity –vs- Entity set Attribute –vs- Relationship Types of attributes and their domain Characteristics of relationships Degree Connectivity Existence

3 Modeling Why would it be necessary or useful to model the structure of a database system?

4 Modeling Data Model Entity-Relationship Diagram (ERD) Popular model that focuses on data

5 ERD ERD: Graphical blueprint for the exact design and structure of a relational DB Shows details of things organization collects data about and how those things are related

6 Relational Database Management System RDBMS A very popular, widely used DBMS Made possible by modern computing power – computer must a lot of processing work User does not need to understand the underlying structure of the database

7 Relational Databases Based on organization of data in two- dimensional tables connected via relationships Tables are linked using a common data element (attribute) that appears in both tables By linking tables via relationships users can navigate the database and extract and combine data from different tables

8 Relational Databases The Table is the fundamental component in a relational database All data are divided into different tables This approach provides a much easier way to manage data Data are essentially grouped by common themes and then connected by relationships in a logical manner based on the ERD

9 Relational Databases A relationship is a connection between two or more simple two-dimensional tables that consist of rows (entity / records) and columns (attributes / fields) of data Each entity is a unique observation and the attributes are the common characteristics that are used to describe all the entities

10 Relational Databases Power of an RDBs comes from ability to quickly find and bring together data stored in separate tables using queries, forms, and reports RDBs utilize the Structured Query Language (SQL) A programming language used to manage data in a RDB

11 Relational Databases CLASS SECTION Table

12 Review What is the entity set represented here? What is an example of an entity within the entity set? What are some of the attributes of the entity? Why is the first field – Employee ID – underlined?

13 Primary Keys Each record/entity must have a attribute (field/column) or set of attributes that uniquely identifies that specific entity from all the other entities stored in the table The unique attribute (or set of attributes) is called the primary key

14 Primary Keys For our purposes: ALL relational DB tables must have a primary key ALL entities within the table must have a unique primary key value The primary can be created by you Doesnt have to provide value-added information Can be a combination of fields/attributes Can be sequential numbers Can be a combination of letters and numbers Cannot be repeated or left blank for an entity

15 Review Key Terminology Entity Set / Table (has a name that directly relates to the primary information stored in the table) Entity / Record (this is a row in a table) Attribute / Field (this is a column in the table that describes a characteristic of the entity) Relationship (an association or linkage between two (+) tables)

16 Different Types of Attributes Simple –vs- composite Single valued –vs- multi-valued

17 Attribute Domain The collection or range of all possible allowable values an attribute may take on EmpDOB: list of all valid employee birth NumDependents: positive integers from 0 to 15 Height: positive real numbers between 36.0 and 84.0 inches. UnionMember: logical yes (true) or no (false) EmpSSN: list of valid social security numbers

18 Value for Each Attribute Each data attribute takes on a specific value: One particular instance of an entitys attribute e.g. Employee attributes: EmpSSNEmpDOBNumDependentsUnionmemberHeight

19 Relationships Entities are connected to one another via relationships The association between two or more entities We will discuss three (3) important characteristics of relationships: 1) Degree 2) Connectivity 3) Existence

20 Relationship Degree Loosely equal to the number of entities involved in a particular relationship Could also view this more simplistically as the number of tables linked by each relationship 1= Unary (aka recursive) 2= Binary 3= Ternary

21 Relationship Connectivity Three types of connectivity relationships are used to describe associations between the entities in different tables How are entities logically connected in the DB? 1) One-to-Many 2) Many-to-Many 3) One-to-One

22 Relationship Connectivity Employee #1 Employee #2 Employee #3 Company Vehicle #1 Company Vehicle #2 Company Vehicle #3 1:1 This relationship connectivity shows that each employee can be associated with only one company vehicle and that each company vehicle can be associated with only one employee. In this case, the RDB will be structured in a manner that matches a specific employee to a specific company car each and every day. Each car would be explicitly linked to a particular employee 1 1 Employee Vehicle

23 Relationship Connectivity Employee #1 Employee #2 Employee #3 Employee #4 Accounting Department Human Resources Dept M This relationship connectivity shows that each employee can be associated with only one organizational department (employees cannot simultaneously be assigned to, or work in, two different departments). However, each department can be staffed with many / multiple employees 1 1:M Employee Department

24 Relationship Connectivity Customer #1 Customer #2 Customer #3 Product #1 Product #2 Product #3 Product #4 M:M This relationship connectivity shows that customer can be associated with many different products and that each product can be associated with many different customers This relationship will be modeled in a special way!! M M Customer Product

25 Relationship Connectivity One-to-Many relationship A professor can teach many different class sections Each class section is taught by only one professor A customer account can contain many invoices Each invoice is associated with only one customer account

26 Relationship Connectivity One-to-Many example Relationship is labeled 1:M Professor Class Section Each teaches M Each is taught by 1 Read: left to right on the top of the line Read: right to left on the bottom of the line

27 Relationship Connectivity Many-to-Many relationship Employee has many job skills Each job skill can be learned by many employees Student can take many class section Each class section can be taken by many students

28 Relationship Connectivity One-to-One relationship Employee is assigned to one Company Car Each Company Car is assigned to only one employee

29 Relationship Connectivity Why does this matter? Logically the relationship needs to make sense Dont want the database functionality to allow relationships that are not feasible or practical From a practical perspective, the foreign key always goes on the many side of the relationship – need to get this correct Special implementation of M:M & 1:1

30 Relationship Existence Denotes whether participation in a relationship is required (or not), and the minimum and maximum number of entities that participate in a particular relationship Mandatory: The existence of one entity depends on the existence of another entity Optional: The existence of one entity is independent of the existence of another entity

31 Mandatory Relationship Existence Example Employee #1 Employee #2 Employee #3 Employee #4 Accounting Department Human Resources Dept 1:M The existence of an instance of employee (an individual employee) depends on the existence of a department where the employee will be assigned In this case, the entity set Department will need to be populated before the entity set Employee is populated Employee Department

32 Optional Relationship Existence Example Employee #1 Employee #2 Employee #3 Employee #4 Accounting Department Human Resources Dept 1:M The existence of an instance of employee (an individual employee) is independent of the existence of a department where the employee will be assigned In this case, the entity instance employee #4 can be created without the need to assign that employee to a department Employee Department

33 Relationship Existence Example CRN 5099 CRN 5060 CRN 5061 CRN 5062 BSAD 141 BSAD 173 BSAD 120 1:M Discuss… Course Section Course

34 Investigating Relationships 1:M relationship This relationship states that each supplier can provide (or distributes) many different products (1, 2, … n), but each individual product is provided by (or distributed by) only one supplier In this case, the structure would not allow a specific product to be provided by (or distributed by) to more than one supplier Supplier Product Can provide M Is provided by 1

35 Supplier Product Can provide M Is provided by 1 Supplier IDCompany NameContact NameContact TitleAddressCityRegionPostal CodeCountryPhone 2 New Orleans Cajun DelightsShelley Burke Order Administrator P.O. Box 78934 New OrleansLA70117USA (100) 555- 4822 3 Grandma Kelly's HomesteadRegina Murphy Sales Representative707 Oxford Rd.Ann ArborMI48104USA (313) 555- 5735 16 Bigfoot BreweriesCheryl Saylor Regional Account Rep. 3400 - 8th Avenue Suite 210BendOR97101USA (503) 555- 9931 Supplier Table

36 Supplier Product Can provide M Is provided by 1 Product Table Product IDProduct Name Supplier IDCategory Quantity Per Unit Unit Price Units In Stock Units On Order Reorder Level 7 Uncle Bob's Organic Dried Pears3Seafood 12 - 1 lb pkgs.$30.0015010 8 Northwoods Cranberry Sauce3 Condiment s 12 - 12 oz jars$40.00600 4 Chef Anton's Cajun Seasoning2 Condiment s 48 - 6 oz jars$22.005300 5 Chef Anton's Gumbo Mix2 Condiment s36 boxes$21.35000 34Sasquatch Ale16Beverages 24 - 12 oz bottles$14.00111015 35Steeleye Stout16Beverages 24 - 12 oz bottles$18.0020015 65 Louisiana Fiery Hot Pepper Sauce2 Condiment s 32 - 8 oz bottles$21.057600 66 Louisiana Hot Spiced Okra2 Condiment s 24 - 8 oz jars$17.00410020

37 Product Table Product IDProduct Name Supplier IDCategory Quantity Per Unit Unit Price Units In Stock Units On Order Reorder Level 7 Uncle Bob's Organic Dried Pears3Seafood 12 - 1 lb pkgs.$30.0015010 8 Northwoods Cranberry Sauce3 Condiment s 12 - 12 oz jars$40.00600 4 Chef Anton's Cajun Seasoning2 Condiment s 48 - 6 oz jars$22.005300 5 Chef Anton's Gumbo Mix2 Condiment s36 boxes$21.35000 34Sasquatch Ale16Beverages 24 - 12 oz bottles$14.00111015 35Steeleye Stout16Beverages 24 - 12 oz bottles$18.0020015 65 Louisiana Fiery Hot Pepper Sauce2 Condiment s 32 - 8 oz bottles$21.057600 66 Louisiana Hot Spiced Okra2 Condiment s 24 - 8 oz jars$17.00410020 Notice that SupplierID is not an attribute of Product – it is the PK of the Supplier table and will be the FK (to the Supplier table) in the Product table

38 Product IDProduct Name Supplier IDCategory Quantity Per Unit Unit Price Units In Stock Units On Order Reorder Level 7 Uncle Bob's Organic Dried Pears3Seafood 12 - 1 lb pkgs.$30.0015010 8 Northwoods Cranberry Sauce3 Condiment s 12 - 12 oz jars$40.00600 4 Chef Anton's Cajun Seasoning2 Condiment s 48 - 6 oz jars$22.005300 5 Chef Anton's Gumbo Mix2 Condiment s36 boxes$21.35000 34Sasquatch Ale16Beverages 24 - 12 oz bottles$14.00111015 35Steeleye Stout16Beverages 24 - 12 oz bottles$18.0020015 65 Louisiana Fiery Hot Pepper Sauce2 Condiment s 32 - 8 oz bottles$21.057600 66 Louisiana Hot Spiced Okra2 Condiment s 24 - 8 oz jars$17.00410020 Supplier IDCompany NameContact NameContact TitleAddressCityRegionPostal CodeCountryPhone 2 New Orleans Cajun DelightsShelley Burke Order Administrator P.O. Box 78934 New OrleansLA70117USA (100) 555- 4822 3 Grandma Kelly's HomesteadRegina Murphy Sales Representative707 Oxford Rd.Ann ArborMI48104USA (313) 555- 5735 16 Bigfoot BreweriesCheryl Saylor Regional Account Rep. 3400 - 8th Avenue Suite 210BendOR97101USA (503) 555- 9931

39 Investigating Relationships The 1:M relationship example The Supplier ID attribute in the Product table is a foreign key that links the individual products in the Product table to a specific supplier in the Supplier table

40 Learning Outcomes 1. Describe the differences between ERDs and DFDs 2. Describe importance of relational DBs 3. Familiar with all terminology: tables, relationships, entities, attributes, keys, etc 4. Understand how to implement a relationship 5. Discuss / define the 3 characteristics of relationships


Download ppt "Entity Relationship Diagrams and Relational DBs BSAD 141 Dave Novak."

Similar presentations


Ads by Google