Presentation is loading. Please wait.

Presentation is loading. Please wait.

Database Administration: The Complete Guide to Practices and Procedures Chapter 3 Data Modeling & Normalization.

Similar presentations


Presentation on theme: "Database Administration: The Complete Guide to Practices and Procedures Chapter 3 Data Modeling & Normalization."— Presentation transcript:

1 Database Administration: The Complete Guide to Practices and Procedures Chapter 3 Data Modeling & Normalization

2 Agenda Data Modeling Concepts The Components of a Data Model Discovering Entities, Attributes & Relationships Conceptual, Logical & Physical Data Models Normalization Additional Data Modeling Issues Questions

3 Don’t think “how”; think “what” Don’t think physical; think conceptual Don’t think process; think structure Don’t think navigation; think relationship Data Thinking http://datatechnologytoday.wordpress.com/2010/12/06/data-modeling-concepts-every-dba-should-know/

4 The Blind Men & The Elephant

5 Data Modeling Objectives Document and communicate the business information requirements Enable databases with: – Minimum redundancy – Maximum integrity – Sharability – Stability – Flexibility – Consistency – Timely access – Usability Increase value of data resource achieves e.g., Data modeling Database Characteristic Database has ObjectiveFunction

6 The Components of a Data Model Data models are comprised of multiple components: Entities Entity Types Entity Occurrences Relationships Attributes Attribute Roles Keys Diagramming Techniques

7 Entities Student Instructor Course Something that exists and is capable of being described. A person, place, thing, concept or event about which an organization maintains facts. Employee Order Item

8 Entity Examples Person: Roles people play Employee Customer Supplier Agent Thing: Physical object type Item Part Product Building Material Equipment Concept: Intangible ideas Warranty Route Account Entity Person PlaceThingEvent Concept Place: Areas or geographic locations Office Warehouse City Region Event: Things that "happen" Sale Order Transfer Shipment Project Agreement Reservation Flight

9 Entity Occurrence Entity Type Entity Occurrences Customer: Moore City: Pittsburgh State: PA Phone: 555 Credit:: Go AMEX: VISA: Contact: Customer: Jackson City: An State: MI Phone: 5 Credit:: Ex AMEX: VISA: Contact: Customer: Mullins City: Houston State: TX Phone: 555-1234 Credit:: Fair AMEX: xxxxxxxxxxxxxxxxxxx VISA: xxxxxxxxxxxxxxxxxxxx Contact: Mike Customer

10 Entity Naming Guidelines Noun, or adjective noun format – Contract – Lease Agreement Minimize use of adjectives – Contractor vs Contract Employee – Training vs Employee Course Do not pluralize; use singular instead: Employee vs Employees – The entity type is a model or pattern rather than the set of all employees Use business terms – Vendor or Supplier? – User or Client? Be consistent Remove process specific artifacts from the entity name – State not Residence State – Agent not Selling Agent

11 Relationships Customer How the different entities are associated with each other CustomerOrder Places Is Placed By Places Is Placed By Order Product

12 One to One Relationship One to Many Relationship Many to Many Relationship Cardinality Mandatory Optional Cardinality 1 Many

13 Entity-Relationship Diagramming is rented under reports to completes rents / is in employed by receives makes rents under is made on is rented as CUSTOMER CustomerNum Name Address Phone CreditCardNum CreditCardExDate StatusCode MOVIE MovieNum Name Director Description Star Rating Genre Rental Rate STORE StoreNum Manager Address Phone EMPLOYEE EmployeeNum Name Address Phone SocialSecNum HireDate Salary Supervisor (FK) PAYMENT Payment Transaction Num Type Amount PaymentDate Status MOVIE RENTAL RECORD Rental Record Date Rental Date Due Date Rental Status Rental Rate Overdue Charge Amt MOVIE COPY Movie Copy Num General Condition JoinDate

14 One-to-OneOne-to-ManyMany-to-Many CUSTOMER ACCOUNTSTUDENTCOURSE 11 1M M M STUDENT 1234512345 COURSE CUSTOMER ACCOUNT EMPLOYEE TEMP_EMP Diagramming Conventions (1) Ross, (2) Bachmann, (3) Martin, (4) Chen, (5) Rumbaugh.

15 UML

16 Data Model Diagram Guidelines Order Customer Order Customer Order Customer Order Reads left-to-right Is placed by Read right-to-left Places Read top-to-bottomRead bottom-to-top Is placed by Places  The relationship is read clockwise over the line

17 Types of Entities Examining relationships can help to determine the type of entity: –Fundamental Entities - represent fundamental, or basic, business objects –Characteristic Entities - contain multiple attributes or facts describing a basic entity –Associative Entities - describe a relationship between two other entities

18 STUDENT StudentID LastName FirstName MiddleInit MajorID ENROLLMENT StudentID CourseNum CourseCompDate Grade COURSE CourseNum CourseName Credits STUDENT StudentID LastName FirstName MiddleInit MajorID COURSE CourseNum CourseName Credits Creating an Associative Entity

19 Attributes  An attribute is a fact about an entity. It is a data element that is an inherent property of an entity.  An attribute will fulfill one (and only one) of these objectives: Identify Relate Describe

20 Attributes Customer: Smith Customer #: 0001 City: New York State: New York Phone: 555-1938 Credit: Good Customer Cust Number Cust Name Street Address City State Zip Code Phone Num Credit Limit Amt Customer Customer: Smith Customer #: 0001 ENTITY = Nouns ATTR = Adjectives

21 Domains The domain defines the universe of valid values for an attribute Each attribute is assigned a domain

22 Attribute Naming Guidelines CLASSABBREVIATIONDESCRIPTION ADDRESSADDRAddress or location AMOUNTAMTMonetary amount CODECODEClassifications, codes, types DATEDATECalendar dates DESCRIPTIONDESCDescriptive text IDENTIFIERIDAlphanumeric unique identifier IMAGEIMGEncoded digital image NAMENAMEAlphabetic name, identification NUMBERNUMNumeric count PERCENTPCTRelationships as % QUANTITYQTYCounts and units TEXTTXTFree form document text TIMETIMETime; temporal data

23 Attribute Values and Null Attributes and attribute values can be thought of in a similar way as entities and entity occurrences An attribute value is an instance of an attribute. If an attribute “value” can be null, it means one of two things: – the attribute is not applicable for certain occurrences of the entity, or – the attribute applies to all entity occurrences, but the information may be unknown. More on Nulls in the next lesson on physical database design

24 Keys  A key is an attribute, or group of attributes, that are used to identify.  There are three types of keys: Candidate Keys Primary Keys Foreign Keys  A key should contain no embedded meaning. The key’s purpose is to identify, not to describe.

25 Primary Keys Customer The attribute or attributes that uniquely identify an entity type A primary key value uniquely identifies a single occurrence of an entity Order Order #: 0001 Line #: 1 ProdID: 1234 Qty: 5 Order Product Customer Number Order Number + Line Number Product ID 0001 / 1

26 Foreign Keys An attribute (or attributes) in one entity that relates an occurrence of that entity to an occurrence of another entity The relating attribute(s) contains the same value(s) as the primary key of the related entity occurrence EmployeeOrg Unit works in employs Emp Num Emp Name Org Unit Num (F) Org Unit Num Org Name EmployeeOrg Unit manages managed by Emp Num Emp Name Org Unit Num Org Name (Relationship Attributes)

27 Candidate Keys There may be multiple possible primary keys – Must identify a specific occurrence of the entity These are known as candidate keys There should be one, and only one, primary key

28 Discovering Entities, Attributes, and Relationships Keep track of the nouns, noun phrases, verbs and adjectives used by subject matter experts Nouns are potential entities & attributes, or perhaps entity occurrences & attribute values Adjectives and prepositional phrases are usually potential attributes Verbs highlight potential relationships Of course, these are not hard & fast rules and you will need to dig for meaning & understanding to build an accurate data model

29 Additional Guidance Put the words in context to further define them Solicit input from multiple sources – Do not rely on just a single subject matter expert Keep patterns in mind

30 Data Model of Modeling Terms Relationship Entity Attribute Occurrence Domain Primary Key Attribute Value

31 Types of Data Models Conceptual – High level Logical – More detailed – No many-to-many relationships – Ready to move to physical Physical – Additional DBMS details – Ready to be implemented as a database

32 Normalization First Normal Form A row is in first normal form if and only if all underlying domains contain atomic values only. Second Normal Form A row is in second normal form if and only if it is in first normal form and every non-key attribute is fully dependent on the key. Third Normal Form A row is in third normal form if and only if it is in second normal form and every non-key attribute is non-transitively dependent on the primary key. The process of identifying the one best place a fact belongs.

33 Unnoramlized STUDENT Data StudentIDStudentNameMajorIDStudentMajorCourseNumCourseNameCourseCompDate 2907Smith, Jacob RMATMathematicsMAT0011Discrete Math2002-08-01 MAT0027Calculus I2002-04-30 EGL0010English Classics I2001-12-30 4019Patterson, Jane KPHIPhilosophyPHI0010Intro to Philosophy2002-04-30 CS00100 Programming Languages 2002-04-30 5145Neeld, Norris BEGLEnglish LiteratureSOC0102Ascent of Man2002-08-01 6132Morrison, Xavier QMUSMusicMUS0002Origin of Jazz2002-04-30 SOC0102Ascent of Man2002-08-01 7810Brown, Richard ECSComputer Science 8966Juarez, SamanthaEGLEnglish LiteratureEGL0010English Classics I2001-12-30 EGL0101Shakespeare II2002-08-01

34 First Normal Form StudentIDLastNameFirstNameMiddleInitMajorIDStudentMajor 2907SmithJacobRMATMathematics 4019PattersonJaneKPHIPhilosophy 5145NeeldNorrisBEGLEnglish Literature 6132MorrisonXavierQMUSMusic 7810BrownRichardECSComputer Science 8966JuarezSamantha EGLEnglish Literature StudentIDCourseNumCourseNameCourseCompDate 2907MAT0011Discrete Math2002-08-01 2907MAT0027Calculus I2002-04-30 2907EGL0010English Classics I2001-12-30 4019PHI0010Intro to Philosophy2002-04-30 4019CS00100Programming Languages2002-04-30 5145SOC0102Ascent of Man2002-08-01 6132MUS0002Origin of Jazz2002-04-30 6132SOC0102Ascent of Man2002-08-01 8966EGL0010English Classics I2001-12-30 8966 EGL0101Shakespeare II2002-08-01 STUDENT COURSE

35 Second Normal Form StudentIDCourseNumCourseCompDate 2907MAT00112002-08-01 2907MAT00272002-04-30 2907EGL00102001-12-30 4019PHI00102002-04-30 4019CS001002002-04-30 5145SOC01022002-08-01 6132MUS00022002-04-30 6132SOC01022002-08-01 8966EGL00102001-12-30 8966EGL01012002-08-01 CourseNumCourseNameCredits MAT0011Discrete Math3 MAT0027Calculus I4 EGL0010English Classics I3 PHI0010Intro to Philosophy3 CS00100Programming Languages3 SOC0102Ascent of Man3 MUS0002Origin of Jazz3 StudentIDLastNameFirstNameMiddleInitMajorIDStudentMajor 2907SmithJacobRMATMathematics 4019PattersonJaneKPHIPhilosophy 5145NeeldNorrisBEGLEnglish Literature 6132MorrisonXavierQMUSMusic 7810BrownRichardECSComputer Science 8966JuarezSamantha EGLEnglish Literature STUDENT COURSE ENROLLMENT

36 Third Normal Form StudentIDCourseNumCourseCompDate 2907MAT00112002-08-01 2907MAT00272002-04-30 2907EGL00102001-12-30 4019PHI00102002-04-30 4019CS001002002-04-30 5145SOC01022002-08-01 6132MUS00022002-04-30 6132SOC01022002-08-01 8966EGL00102001-12-30 8966EGL01012002-08-01 CourseNumCourseNameCredits MAT0011Discrete Math3 MAT0027Calculus I4 EGL0010English Classics I3 PHI0010Intro to Philosophy3 CS00100Programming Languages3 SOC0102Ascent of Man3 MUS0002Origin of Jazz3 StudentIDLastNameFirstNameMiddleInitMajorID 2907SmithJacobRMAT 4019PattersonJaneKPHI 5145NeeldNorrisBEGL 6132MorrisonXavierQMUS 7810BrownRichardECS 8966JuarezSamantha EGL STUDENT COURSE ENROLLMENT MajorIDStudentMajor MATMathematics PHIPhilosophy EGLEnglish Literature MUSMusic CSComputer Science MAJOR

37 MajorID Major STUDENT StudentID LastName FirstName MiddleInit MajorID ENROLLMENT StudentID CourseNum CourseCompDate COURSE CourseNum CourseName Credits The Data Model in Third Normal Form

38 Further Normal Forms Boyce Codd normal form (BCNF) – A further refinement of 3NF. Indeed, in his later writings Codd refers to BCNF as 3NF. A row is in Boyce Codd normal form if and only if every determinant is a candidate key. Most entities in 3NF are already in BCNF. Fourth normal form (4NF) – No entity can have more than a single one-to-many relationship if the one-to-many attributes are independent of each other. An entity is in 4NF if and only if it is in 3NF and has no multiple sets of multivalued dependencies. Fifth normal form (5NF) – Every join dependency for the entity must be a consequence of its candidate keys.

39 Normalization in Practice Normalization ensures that we are creating a data blueprint for the best database design possible. Normalization is a logical process. – Many times data modelers will try to mandate that the logical model become the physical database design with no changes. But it is not wise to force DBAs and technicians to forgo physical design. In the best of all worlds, a one-to-one logical to physical translation would work, but for many reasons, this strict one-to-one mapping is not practical. The only normal form required for relational databases is First Normal Form. 1NF ensures tabular data.

40 Additional Data Modeling Issues Subtypes and super-types Handling time One-to-one relationships? Derived data (see next slide)

41 Derived and Base Data Student ID Student Name Student Date of Birth Student Age(D) Course Course Num Course Offering Date Course Name Course Fee Student ID Course Num Course Offering Date Course Completion Date Course Charge Back Amt(DT) Enrollment Student

42 Questions


Download ppt "Database Administration: The Complete Guide to Practices and Procedures Chapter 3 Data Modeling & Normalization."

Similar presentations


Ads by Google