Yes! Database Design can be this fun<br />Mark Abramson, CEO, Forward Thought, Inc.<br />10/9/2011<br />© 2011 Mark Abrams...
THEORY & ELEMENTS <br />DEMO<br />Q&A<br />10/9/2011<br />© 2011 Mark Abramson / #svcc<br />2<br />Edgar F Codd<br />
Microsoft BizSpark Startup Partner<br />Organizer of BizSparkSFMeetup Group<br />Regular customer of all tools used in dem...
What is a database design?<br />10/9/2011<br />© 2011 Mark Abramson / #svcc<br />4<br />
Why Database Design?<br />Gives everyone a clear picture of your business rules and the data behind it<br />Build consensu...
Entity / Relationship Model<br />An Entity is some “thing” of interest<br />A Relationship defines the interaction between...
What’s the data look like?<br />10/9/2011<br />© 2011 Mark Abramson / #svcc<br />7<br />
Entity<br />Definition<br />Attributes<br />Data Types<br />NULL option<br />Primary Key<br />Foreign Key<br />Identity Co...
Relationship<br />Definition<br />Identifying<br />Non-Identifying<br />10/9/2011<br />© 2011 Mark Abramson / #svcc<br />9...
Relationship (2)<br />Recursive references<br />Associative / Many-To-Many /“Join Tables”<br />10/9/2011<br />© 2011 Mark ...
Cardinality<br />How many instances of each entity may be involved or must be involved?<br />10/9/2011<br />© 2011 Mark Ab...
Keys<br />Primary Keys<br />Foreign Keys<br />Candidate Keys<br />Composite Keys<br />10/9/2011<br />© 2011 Mark Abramson ...
Normalization<br />10/9/2011<br />© 2011 Mark Abramson / #svcc<br />13<br />Denormalization<br />Normalization<br />
Getting Fancy<br />First, second, third-normal form<br />Generalization<br />Nonspecific relations<br />Three-way relation...
Exercise! Legacy Baggage<br />10/9/2011<br />© 2011 Mark Abramson / #svcc<br />15<br />
Tools for Creating Your Model<br />Paper + Pen / Whiteboard<br />Drawing Tools: PowerPoint, Visio<br />ER Tools: Open Sour...
Demo time!<br />SQL Server Management Studio (“free”)<br />http://www.microsoft.com/download/en/details.aspx?id=7593<br />...
Resources<br />10/9/2011<br />© 2011 Mark Abramson / #svcc<br />18<br />Designing Quality Databases With Idef1X Informatio...
10/9/2011<br />© 2011 Mark Abramson / #svcc<br />19<br />SV Code Camp<br />Peter Kellner<br />Edgar Codd<br />Attendees<br...
Upcoming SlideShare
Loading in …5
×

Introduction to Database Design with Entity Relationship Diagrams

4,904 views

Published on

This presentation was delivered to the Silicon Valley Code Camp in a session entitled "Introduction to Database Design with Entity Relationship Diagrams" on October 9, 2011. The intent of the presentation is to teach people how to understand, create and work with ER diagrams. There are also a number of topics introduced for the purpose of stimulating self-directed learning after the presentation.

The presentation featured a demo where the audience participated in the design and normalization of a database in real time.

Published in: Technology
0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
4,904
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
86
Comments
0
Likes
5
Embeds 0
No embeds

No notes for slide
  • 25-30 minutes of instruction, 15-20 minutes of demo, 30+ minutes of Q&amp;AI hope I’ll address most of your questions, so write them down + let’s talk about them at the end of the slidesBut if you don’t understand something, please interruptFirst off, I’d like to see where you’re at – where are you with your understanding and experience w/modeling?Comfy with SQL? Write a join query? Have done modeling before? Dealing with someone else’s mess
  • Edgar F.Codd – British IBM researcher, regarded as the inventor of the relational model for database managementGOALS FOR SESSION: At the end of this session, you should be able to read, understand and create database Entity Relationship diagramsThere will be a couple of exercises for the audience as we go and an Interactive demoQ&amp;A – very curious about what you’re facing out there in the world
  • Want you to know of any bias that may affect my talkCheck out November 7thMeetup all about Tools, Tools and More Toolswww.bizsparksf.com
  • Visual representation of the ENTITIES and RELATIONSHIPS between themBased on rules from the real world / your business; Entails a number of rules, standards and guidelinesGreat way to communicate with co-workers, customers, developers; Great working model and critical reference documentYou could consider this as a whole bunch of linked-together Excel worksheets: these fields define the columnsWorking with a model is 50% science, 50% art, 50% experience
  • C’mon, you have to put all that data *somewhere*!Fun? YES! It’s a great mental exercise that forces you to think through a lot of hard problemsSeparation of Concerns (1974, check Wikipedia)
  • Entity = object that is important to the business.Entity = the NOUNRelationship = how are these objects/entities relating to one another?Relationship = the VERB; the VERB PHRASE
  • CustomerId in SalesOrder table references a record/row in the Customer tableWe can look up / refer to related or seemingly unrelated data elsewhere
  • What’s in a name?Naming conventions – singular vs. plural DESCRIBE THE BUSINESSAttribute = property of an Entity = Columns of database tableData type choice (decimal vs. float vs. money) varchar vs. nvarchar vs. char vs. textNULL option – is this attribute mandatory or required per business rules?Primary Key: unique identifier for each row of dataForeign Key: some other entity’s primary key that appears here due to some relationship between the twoIDENTITY column: guarantees uniqueness and auto-increments (autonumber). (1,1) specifies the SEED and INCREMENT
  • Not just a Facebook statusA relationship is the “verb” between entities – defines how they interact per business rulesNaming / “writing a sentence”Defines how the entities interactRead the relationship from parent-&gt;child (end with the dot)Identifying: the child is dependent on its parent for its identityNon-identifying: may be existence dependent but not identity dependent
  • Sometimes we end up with odd relationships and don’t know whyAssociative / link / join / junction table: used for many-to-many tablesCan make joins a little more difficult but is a common patternGREAT for when you want to use an entity in other areas, e.g. Customer&lt;-&gt;Address and Person&lt;-&gt;Address
  • Cardinality: how many instances of each entity may be involved or must be involved?w/ identifying – there has to be one Customer for some # of Addressw/ non-identifying – no requirement to have a Customer to have an Address (could be an Employee Address, Order Address, etc.)&lt;nothing&gt; One-to-zero-or-more:&lt;P&gt; one to one or more&lt;Z&gt; one to zero or one&lt;N&gt; one to exactly Nw/ non-identifying relationships, these can all be zero-or-one-to…
  • Primary Key – unique identifying key (can be any data type as long as it’s unique)Foreign Key – some other entity’s PK that appears here because of some relationship with itCandidate Key – Could this work as a PK? What’s are the candidate keys in this table?Composite Key – put a few fields together to get a unique keyStrings? Timestamps? Integers? Decimals?
  • DENORMALIZED:Data can be duplicated and get out of syncEase of queryingPerformance considerationsNORMALIZED:One “fact” occurs in one place and only one placeRequires you to get the business rules “right”No way to have data concurrency issuesDoes require a lot of joins
  • Great opportunities for self-directed learningCascading deletes
  • In some ways it’s easier to create than repair… let’s work together to see how we can improve this modelFirstName/LastName fields long enough?StateProvince field?Website (255) OK?Are all of these fields really OK to be nulls?WTF is OwnerId doing in Country? State?Is StateCode and CountryCode OK for a PK? Why not a bigint?Relationships in wrong directionDenormalizedInfo? What is this? A flag?
  • Features + benefits of these as you go up/down the food chain
  • Introduction to Database Design with Entity Relationship Diagrams

    1. 1. Yes! Database Design can be this fun<br />Mark Abramson, CEO, Forward Thought, Inc.<br />10/9/2011<br />© 2011 Mark Abramson / #svcc<br />1<br />@mark__a<br />
    2. 2. THEORY & ELEMENTS <br />DEMO<br />Q&A<br />10/9/2011<br />© 2011 Mark Abramson / #svcc<br />2<br />Edgar F Codd<br />
    3. 3. Microsoft BizSpark Startup Partner<br />Organizer of BizSparkSFMeetup Group<br />Regular customer of all tools used in demo<br />Schema-first kind of guy<br />10/9/2011<br />© 2011 Mark Abramson / #svcc<br />3<br />Disclosures<br />
    4. 4. What is a database design?<br />10/9/2011<br />© 2011 Mark Abramson / #svcc<br />4<br />
    5. 5. Why Database Design?<br />Gives everyone a clear picture of your business rules and the data behind it<br />Build consensus across business units<br />Separation of concerns<br />Ensure data accuracy<br />Fun<br />10/9/2011<br />© 2011 Mark Abramson / #svcc<br />5<br />
    6. 6. Entity / Relationship Model<br />An Entity is some “thing” of interest<br />A Relationship defines the interaction between one or more Entities<br />10/9/2011<br />© 2011 Mark Abramson / #svcc<br />6<br />
    7. 7. What’s the data look like?<br />10/9/2011<br />© 2011 Mark Abramson / #svcc<br />7<br />
    8. 8. Entity<br />Definition<br />Attributes<br />Data Types<br />NULL option<br />Primary Key<br />Foreign Key<br />Identity Columns<br />10/9/2011<br />© 2011 Mark Abramson / #svcc<br />8<br />
    9. 9. Relationship<br />Definition<br />Identifying<br />Non-Identifying<br />10/9/2011<br />© 2011 Mark Abramson / #svcc<br />9<br />Non-Identifying Relationship<br />
    10. 10. Relationship (2)<br />Recursive references<br />Associative / Many-To-Many /“Join Tables”<br />10/9/2011<br />© 2011 Mark Abramson / #svcc<br />10<br />
    11. 11. Cardinality<br />How many instances of each entity may be involved or must be involved?<br />10/9/2011<br />© 2011 Mark Abramson / #svcc<br />11<br />
    12. 12. Keys<br />Primary Keys<br />Foreign Keys<br />Candidate Keys<br />Composite Keys<br />10/9/2011<br />© 2011 Mark Abramson / #svcc<br />12<br />
    13. 13. Normalization<br />10/9/2011<br />© 2011 Mark Abramson / #svcc<br />13<br />Denormalization<br />Normalization<br />
    14. 14. Getting Fancy<br />First, second, third-normal form<br />Generalization<br />Nonspecific relations<br />Three-way relationships<br />Constraints<br />Referential Integrity actions<br />Zachman’s Framework<br />10/9/2011<br />© 2011 Mark Abramson / #svcc<br />14<br />
    15. 15. Exercise! Legacy Baggage<br />10/9/2011<br />© 2011 Mark Abramson / #svcc<br />15<br />
    16. 16. Tools for Creating Your Model<br />Paper + Pen / Whiteboard<br />Drawing Tools: PowerPoint, Visio<br />ER Tools: Open Source / Community Editions<br />CA ERWin; Toad; SSMS; MySQL Workbench<br />ER Tools: Midrange<br />Sparx Systems EA $199; Toad $479<br />ER Tools: High End<br />CA ERWin $4000; Embarcadero $2000<br />10/9/2011<br />© 2011 Mark Abramson / #svcc<br />16<br />
    17. 17. Demo time!<br />SQL Server Management Studio (“free”)<br />http://www.microsoft.com/download/en/details.aspx?id=7593<br />RedGate SQL Data Generator ($295)<br />http://www.red-gate.com/products/sql-development/sql-data-generator/<br />RedGate SQL Prompt Pro ($295)<br />http://www.red-gate.com/products/sql-development/sql-prompt/<br />10/9/2011<br />© 2011 Mark Abramson / #svcc<br />17<br />
    18. 18. Resources<br />10/9/2011<br />© 2011 Mark Abramson / #svcc<br />18<br />Designing Quality Databases With Idef1X Information Models<br />Thomas A., M.D. Bruce<br />$3.91 on Amazon!<br />SQL in a Nutshell: A Desktop Quick Reference<br />Kevin Kline, Brand Hunt, Daniel Kline<br />$18 on Amazon<br />The Data Model Resource Book, Vol. 1: A Library of Universal Data Models for All Enterprises<br />Len Silverston<br />$45<br />(also check out Vol. 2 and Vol. 3)<br />http://www.databaseanswers.org/data_models<br />Repository of simple examples of db models<br />Free!<br />http://publib.boulder.ibm.com/infocenter/wchelp/v5r6/index.jsp?topic=/com.ibm.commerce.data.doc/refs/rdmindex.htm<br />IBM WebSphere data model<br />Also search for ER Diagrams for other large systems to see how someone else addressed a set of entities and relationships (MS Dynamics, SAP, etc.)<br />Image Credits<br />Slide 1: flickr/besser.jetzt<br />Slide 2: IBM<br />Slide 3: flickr/Pete Reed<br />Slide 4: flickr/Artful Magpie<br />Slide 14: Amazon.com<br />Slide 15: flickr/Jon Ashcroft<br />All ER diagrams: Mark Abramson<br />www.StackOverflow.com<br />
    19. 19. 10/9/2011<br />© 2011 Mark Abramson / #svcc<br />19<br />SV Code Camp<br />Peter Kellner<br />Edgar Codd<br />Attendees<br />Loving Wife<br />Thomas Bruce<br />Mom + Dad<br />

    ×