An Introduction to Data Modelling Entity Relationship Modelling Avin Mathew amathew@smsmt.com Nov 2010 WHY do we model data? 2 WHAT is a data model? 3 An album has an a creating artist, a title, recommended price, genre and album art that is displayed to a user. A user can subsequently purchase the album in various quantities and at different unit prices depending on specials on offer. A user’s purchase order will contain the date of purchase, their contact details (address, telephone and/or email) and the total price. 4 OrderDetail Album PK OrderDetailId PK AlbumId FK1 FK2 OrderId AlbumId Quantity UnitPrice FK1 FK2 GenreId ArtistId Title Price AlbumArtUrl Order PK OrderId Date Username Name Address Phone Email Total Genre PK GenreId Name Description Artist PK ArtistId Name WHERE do we use data models? 6 WHEN would a Business Analyst use data models? 7 Data Model Levels Conceptual Logical Physical How do we data model? • People • Business, users, developers, DBAs • Inputs • Business & functional requirements, business processes, databases, documents, UI screens • Tools • Drawing packages (e.g. PowerPoint, Visio), data modelling packages (e.g. ERWin, System Architect) Entity Relationship Model • Most common data modelling technique • Used in most business information system development • Tools that engineer a database from a data model ER Process 1. Identify entities 2. Identify attributes 3. Identify relationships 4. Apply naming conventions 5. Assign keys 6. Normalise Identify entities • An object that exists and is distinguishable from other objects • Examples: person, company, event, place • Should be a singular concept Entity Name Person Chair Entity Name 12 Identify attributes • Properties of an entity Person Attribute Name First Name Last Name Email Address Chair Colour Height Price Attribute Name 13 Identify relationships • An association between two entities • Cardinality and optionality • One to one Person • One to many Chair Person Table • Many to many Phone Number Person • Roles Person Person Person Phone Number Phone Number Chair sits on 14 Apply naming conventions Examples: • Singular vs plural names for entities • Consistent names: date, summary, description, name • Reference Types all ending with Type • Standardise suffixes: Id, Key, Code, Flag 15 Assign keys Primary Key Person PK Natural Key Foreign Key FK1 Tax File Number First Name Middle Names Last Name Address Id Address PK Address Id Address Line 1 Address Line 2 Suburb State Post Code Primary Key Surrogate Key 16 Normalise • Every non-key attribute in every table is directly dependent on the key • Results in: • Elimination of redundancies • Fewer anomalies • Most information systems are in third-normal form 17 Scenario 1 18 Scenario 1 – A Possible Data Model Electrical Incident Location Incident Location Id Name Incident Date Summary Description Dangerous Event Flag Reported By Supervising Officer Environmental Incident Investigation Investigator Person Type Motor Vehicle Incident Person Bodily Location Bodily Location Type Injury/Illness Incident Description Person Id Classification First Name Last Name Person Injured/Ill Nature Nature Type 19 Scenario 2 20 Scenario 2 – A Possible Data Model Asset Type Segment Installation History Agent Install Date Uninstall Date Model Asset Product Family Revision Number Manufacturer Serial Number Attribute Type Attribute Unit Type Value 21 Data Model Patterns David Hay – Data model patterns: Conventions of thought Martin Fowler – Analysis patterns: Reusable object models Len Silverston – The data model resource book: A library of universal data models for all enterprises An Introduction to Data Modelling Entity Relationship Modelling Avin Mathew amathew@smsmt.com Nov 2010