Vous êtes sur la page 1sur 35

Introduction to

Data Modeling with


MySQL Workbench
Presented By:

Mike Hillyer
Mike Zinner

and
The MySQL Workbench Team

1
Who Are We?
 Mike Hillyer
 Former MySQL AB Technical Writer, GUI Tools
 http://www.mikehillyer.com

 Mike Zinner
 Team Lead, Developer Tools
 http://zinner.org

 Alfredo Kojima
 Senior Software Engineer, Developer Tools

 Johannes Taxacher
 QA Engineer, Developer Tools

2
Who Are You?

 How Many Of You:

 Are Here for Data Modeling?


 Are Here for MySQL Workbench?
 Are Here for Both?

 Are Database Designers?


 Are Developers?

 Have used MySQL Workbench?

 Secret Plan: You are Guinea Pigs

3
What is This Session About?
 An introductory session for those new to both data
modeling and MySQL Workbench

 Covers:
 Designing a schema
 Introduction to workbench
 Designing a schema with WB
 How to normalize a schema
 Performance Optimizations
 Advanced Workbench Usage
 Q&A
 Conclusion

4
Workbench Install

 Go to http://dev.mysql.com/workbench/
UC09Workbench.php to download installer

 Alternatively collect a thumbdrive, installers are


included for all supported platforms

 Please raise your hand for install assistance

 Windows users will need the .NET Framework 2.0


and the VS2005.net Redistributable. Both are found
at microsoft.com/downloads and on the thumb drives

5
Introducing MySQL Workbench

 DBDesigner4 brought Mike Zinner to MySQL AB

 MySQL GUI team developed Query Browser,


Administrator, Windows Installer and finally MySQL
Workbench

 MySQL Workbench is a visual database design tool

 Workbench provides tools for design, change


management, documentation

 Workbench is extensible using Lua, Python and C++

6
MySQL Workbench Goals
 Productivity for MySQL Developers & DBAs
 Save time when working with big schemata
 Make it easy to visualize and tune schemata

 Give Developers the tool they really need


 Done by developers for developers
 Native on each platform - best user experience!

 Make MySQL easier to use


 GUI Tools 2nd biggest download on MySQL.com
 Best selling product in the MySQL online shop

7
MySQL Workbench Editions
 MySQL Workbench OSS (Community Edition)
 MySQL Workbench SE (Standard Edition)
 $99/Developer/Year subscription
 $2,500...$20,000/Company/Year for Unlimited sub.

8
MySQL Workbench Standard Edition
 Commercial extension of OSS version
 Added features:
 Schema object privilege system
 Schema validation plugins
 Model reporting
 Online printing
 Reverse engineering
 Synchronization (against live database connections)

 Purchase for annual subscription fee of $99


 Downloadable from website
 http://mysql.com/products/workbench/features.html
9

9
Usage Walkthough

10
Exercise

 Build a schema to track surveys and responses.


 Record surveys with descriptions
 Record questions, potential pre-defined multiple
choice answers, allow for written response
 Record responses to questions, attach them to
individual responders

11
Data Types

 Use Appropriate Data Type – when data type is


wrong can lead not only to compromised data, but
additional processing to convert the string to a
numeric value prior to performing calculations
 Use Appropriate Length – a length that has a max
value so high would be inappropriate for data that
would max out much smaller
 Use Not Null – a column with NULL capability that
will never contain a NULL can cause integrity issues
and add unnecessary processes

12
Normalize Your Schema
 What is Normalization?

 Introduced by E.F. Codd

 The modification of a schema so that it conforms to


defined normal forms.

 Ensuring that every non-key column relates to


“The Key, The Whole Key, and Nothing But the Key”
 So Help Me Codd

 Makes data atomic.


 Reduces redundancy.

13
Benefits of Normalization
 Decreased storage consumption.
 Removed redundancy means less data.

 Better/Faster(/Stronger) searches.
 Less data to scan.
 Easier searches on (previously) mixed data.

 Improved data integrity.


 When data is only in one place you only have to get
it right/fix it once.

14
The Normal Forms

 First Normal Form (1NF)

 Second Normal Form (2NF)

 Third Normal Form (3NF)

15
First Normal Form (1NF)

 Requires a Primary Key. (The Key)


 Requires that all data is atomic.

 Also work on removing horizontal and vertical


redundancies from your table.

Name ID First_Name Last_Name


Mike Hillyer 1 Mike Hillyer

16
Second Normal Form (2NF)
 Requires that all fields relate to an entire
composite key, not just parts. (The Whole Key)

Reviewer_ID First_Name Last_Name ISBN Score

1 Mike Hillyer 2233 4.5

Reviewer_ID ISBN Score


1 2233 4.5

17
Third Normal Form (3NF)
 Requires that all fields depend directly on the primary
key, and not on other non-key fields.
 (And Nothing But The Key)

Address_ID Address City State Zip

1 123 Main Street Santa Clara California 90221

Zip City State

90221 Santa Clara California

18
Additional Normal Forms

 Boyce-Codd Normal Form


 Fourth Normal Form
 Fifth Normal Form
 Domain/Key Normal Form
 Sixth Normal Form
 Non-First Normal Form

 http://en.wikipedia.org/wiki/Database_normalization

19
By Example: User Tracking
 Table has no Primary Key.
 Name is not atomic.
 Table starts with all possible user
information in a single table.
 Phone numbers and email addresses
are horizontally redundant.
 Company, department, city, state, zip
are vertically redundant.

20
1NF Satisfied

21
2NF Satisfied

22
3NF Satisfied

23
Over-Normalization

24
De-Normalization
 Start by normalizing, then watch your slow query logs
and run EXPLAIN.

 De-Normalization may be needed on certain queries


(joining and sorting).

 Maintain data integrity with triggers.

 Alternatively try using a view first to bring data


together.

25
Think Outside the Database
 Consider whether the data in question needs to be
stored in the database at all

 Can/should a slow query be cached outside the


database, perhaps even client-side

 Recommended reading -->

26
How to De-Normalize
 Combine one-to-many relationships - there are
times when a single column should be added to the
“many” table to remove the need to have a join

 Add Attributes – add additional columns to an


existing table to improve performance by minimizing
the need for a join

 Data Snapshot - create a table that stores a


snapshot of data that needs to be retrieved through
multiple methods

27
Managing Schema Privileges

 Add Users to design to manage their privileges

 Add Roles to simply management of privileges

28
Maintaining Your Design

 Whenever possible make your changes in the design,


then update the database from Workbench

 Test your changes in a staging environment first

 Use the sync tool to implement changes from the


design or update the design with changes made to
the database

29
Document Your Schema

 Generate automatic documentation using DBDoc tool

 Use model notes to keep track of important


information

 Use layers to logically group objects

 Print out your schema for easy developer reference

30
31
Using Advanced Features

 Export ORM Schemas Directly from Workbench


Using Community Plugins:

http://forums.mysql.com/read.php?153,208229

 Use custom Add-ons to perform new tasks:

http://dev.mysql.com/workbench//?p=190

32
The Future of WB: RoadMap

 WB 5.2 “Query”, Q3/09


 Database querying, Administration Plugin

 WB 6.0 “SQL IDE”, Q2/10


 SQL Re-factoring, Query Builder

 WB 6.1 “Team”, Q3/10


 Workgroup support, Versioning

 Coming up next:
 Multi RDBMS support
 Logical modeling
 Advanced migration

33
Q&A

 Any Questions?

 Ask now or catch us during the conference!

34
Conclusion

 Thanks for Coming!

 Please check http://mikehillyer.com/presentations


for the slides and recording of this presentation

 Watch http://wb.mysql.com/
for news and developments

35

Vous aimerez peut-être aussi