Presentation is loading. Please wait.

Presentation is loading. Please wait.

2006­02-08 | Database Normalization | © MySQL AB 2006 | www.mysql.com 1 An Introduction to Database Normalization Mike Hillyer – MySQL AB.

Similar presentations


Presentation on theme: "2006­02-08 | Database Normalization | © MySQL AB 2006 | www.mysql.com 1 An Introduction to Database Normalization Mike Hillyer – MySQL AB."— Presentation transcript:

1 2006­02-08 | Database Normalization | © MySQL AB 2006 | www.mysql.com 1 An Introduction to Database Normalization Mike Hillyer – MySQL AB

2 2006­02-08 | Database Normalization | © MySQL AB 2006 | www.mysql.com 2 About Me Member of the MySQL AB documentation team MySQL Core and Pro Certified MySQL expert at www.experts-exchange.com Resident MySQL expert at SearchOpenSource.com http://www.openwin.org/mike/index.php/about-me/ Mike Hillyer, BSc

3 2006­02-08 | Database Normalization | © MySQL AB 2006 | www.mysql.com 3 About You Currently use MySQL? Another RDBMS? Are responsible for database design? Will be in the future? Know about database normalization? How many of you…

4 2006­02-08 | Database Normalization | © MySQL AB 2006 | www.mysql.com 4 About This Session http://www.openwin.org/mike/index.php/presentations/ http://dev.mysql.com/tech-resources/articles/intro-to-normalization.html Introduction What Is Database Normalization? What are the Benefits of Database Normalization? What are the Normal Forms? First Normal Form Second Normal Form Forming Relationships Third Normal Form Joining Tables De-Normalization Conclusion

5 2006­02-08 | Database Normalization | © MySQL AB 2006 | www.mysql.com 5 What Is Database Normalization? Cures the ‘SpreadSheet Syndrome’ Store only the minimal amount of information. Remove redundancies. Remove anomalies. Restructure data.

6 2006­02-08 | Database Normalization | © MySQL AB 2006 | www.mysql.com 6 What are the Benefits of Database Normalization? Decreased storage requirements! 1 VARCHAR(20) converted to 1 TINYINT UNSIGNED in a table of1 million rows is a savings of~20 MB Faster search performance! –Smaller file for table scans. –More directed searching. Improved data integrity!

7 2006­02-08 | Database Normalization | © MySQL AB 2006 | www.mysql.com 7 What are the Normal Forms? First Normal Form (1NF) Second Normal Form (2NF) Third Normal Form (3NF) Boyce-Codd Normal Form (BCNF) Fourth Normal Form (4NF) Fifth Normal Form (5NF) Sixth Normal Form (6NF)

8 2006­02-08 | Database Normalization | © MySQL AB 2006 | www.mysql.com 8 Our Table TitleAuthorBioISBNSubjectPagesPublisher Beginning MySQL Database Design and Optimization Chad Russell Jon Stephens Chad Russell is a programmer and network administrator who owns his own Internet hosting company. Jon Stephens is a member of the MySQL AB documentation team. 1590593324 MySQL Database Design 520Apress

9 2006­02-08 | Database Normalization | © MySQL AB 2006 | www.mysql.com 9 First Normal Form All values must be atomic Each row must be unique –Use a primary key Benefits –Easier to query/sort the data –More scalable –Each row can be identified for updating

10 2006­02-08 | Database Normalization | © MySQL AB 2006 | www.mysql.com 10 Satisfying 1NF ISBNTitlePages 1590593324 Beginning MySQL Database Design and Optimization 520 Book Author_I D First_NameLast_name 1ChadRussell 2JonStephens 3MikeHillyer Author Subject_IDName 1MySQL 2Database Design Subject Publisher_IDNameAddressCityStateZip 1Apress 2560 Ninth Street, Station 219 BerkeleyCalifornia94710 Publisher

11 2006­02-08 | Database Normalization | © MySQL AB 2006 | www.mysql.com 11 Forming Relationships Three Forms –One to (zero or) One –One to (zero or) Many –Many to Many One to One –Same Table? One to Many –Place PK of the One in the Many Many to Many –Create a joining table

12 2006­02-08 | Database Normalization | © MySQL AB 2006 | www.mysql.com 12 Many-to-Many (Joining Tables) ISBNAuthor_ID 15905933241 2 ISBNSubject_ID 15905933241 2 Book_Author Book_Subject

13 2006­02-08 | Database Normalization | © MySQL AB 2006 | www.mysql.com 13 One-To-Many ISBNTitlePagesPublisher_ID 1590593324 Beginning MySQL Database Design and Optimization 5201 Book

14 2006­02-08 | Database Normalization | © MySQL AB 2006 | www.mysql.com 14 Second Normal Form Table must be in First Normal Form Composite keys –All columns in a row must refer to the entire key Benefits –Increased storage efficiency –Less data repetition ISBNAuthor_IDSummaryAuthor_URL 15905933243A great book!http://www.openwin.org Review

15 2006­02-08 | Database Normalization | © MySQL AB 2006 | www.mysql.com 15 Third Normal Form Table must be in Second Normal Form –If your table is 2NF, there is a good chance it is 3NF All columns must depend directly on the primary key “The key, the whole key, and nothing but the key” Benefits –No extraneous data

16 2006­02-08 | Database Normalization | © MySQL AB 2006 | www.mysql.com 16 Satisfying Third Normal Form Publisher_IDNameAddressZip 1Sams Publishing800 East 96th Street46240 Publisher ZipCityState 46240IndianapolisIndiana Zip

17 2006­02-08 | Database Normalization | © MySQL AB 2006 | www.mysql.com 17 Finding Balance

18 2006­02-08 | Database Normalization | © MySQL AB 2006 | www.mysql.com 18 Joining Tables Two Basic Joins –Inner-Join –Outer Join LEFT OUTER JOIN RIGHT OUTER JOIN FULL OUTER JOIN

19 2006­02-08 | Database Normalization | © MySQL AB 2006 | www.mysql.com 19 Inner Join mysql> SELECT First_Name, Last_Name, ISBN -> FROM Author INNER JOIN Book_Author ON Author.Author_ID = Book_Author.Author_ID; +------------+-----------+------------+ | First_Name | Last_Name | ISBN | +------------+-----------+------------+ | Chad | Russell | 1590593324 | | Jon | Stephens | 1590593324 | +------------+-----------+------------+ 2 rows in set (0.05 sec)

20 2006­02-08 | Database Normalization | © MySQL AB 2006 | www.mysql.com 20 LEFT OUTER JOIN mysql> SELECT First_Name, Last_Name, ISBN -> FROM Author LEFT OUTER JOIN Book_Author ON Author.Author_ID = Book_Author.Author_ID; +------------+-----------+------------+ | First_Name | Last_Name | ISBN | +------------+-----------+------------+ | Chad | Russell | 1590593324 | | Jon | Stephens | 1590593324 | | Mike | Hillyer | NULL | +------------+-----------+------------+ 3 rows in set (0.00 sec)

21 2006­02-08 | Database Normalization | © MySQL AB 2006 | www.mysql.com 21 De-Normalizing Tables Use with caution Normalize first, then de-normalize Use only when you cannot optimize Try temp tables, UNIONs, VIEWs, subselects first

22 2006­02-08 | Database Normalization | © MySQL AB 2006 | www.mysql.com 22 Conclusion http://dev.mysql.com/tech-resources/articles/intro-to- normalization.html MySQL Database Design and Optimization –Jon Stephens & Chad Russell –Chapter 3 –ISBN 1-59059-332-4 –http://www.openwin.org/mike/books http://www.openwin.org/mike/index.php/presentations

23 2006­02-08 | Database Normalization | © MySQL AB 2006 | www.mysql.com 23 QUESTIONS? Feel free to ask now or find me after this session!


Download ppt "2006­02-08 | Database Normalization | © MySQL AB 2006 | www.mysql.com 1 An Introduction to Database Normalization Mike Hillyer – MySQL AB."

Similar presentations


Ads by Google