relational databases - northwestern university · 2013-01-30 · • best practices for database...
TRANSCRIPT
![Page 1: RELATIONAL DATABASES - Northwestern University · 2013-01-30 · • Best practices for database design ... • Combines the talkers, sentence and sentenceProduction table and only](https://reader034.vdocuments.site/reader034/viewer/2022050411/5f87f749a74a634c6c685615/html5/thumbnails/1.jpg)
RELATIONAL DATABASES SCRG Lab Group Demo, 23 Jan 2012
![Page 2: RELATIONAL DATABASES - Northwestern University · 2013-01-30 · • Best practices for database design ... • Combines the talkers, sentence and sentenceProduction table and only](https://reader034.vdocuments.site/reader034/viewer/2022050411/5f87f749a74a634c6c685615/html5/thumbnails/2.jpg)
Outline • Why use a relational database • Best practices for database design • Working with a relational database (MySQL and
phpMyAdmin)
![Page 3: RELATIONAL DATABASES - Northwestern University · 2013-01-30 · • Best practices for database design ... • Combines the talkers, sentence and sentenceProduction table and only](https://reader034.vdocuments.site/reader034/viewer/2022050411/5f87f749a74a634c6c685615/html5/thumbnails/3.jpg)
Outline • Why use a relational database • Best practices for database design • Working with a relational database (MySQL and
phpMyAdmin)
![Page 4: RELATIONAL DATABASES - Northwestern University · 2013-01-30 · • Best practices for database design ... • Combines the talkers, sentence and sentenceProduction table and only](https://reader034.vdocuments.site/reader034/viewer/2022050411/5f87f749a74a634c6c685615/html5/thumbnails/4.jpg)
A systematic framework for storing and managing data
![Page 5: RELATIONAL DATABASES - Northwestern University · 2013-01-30 · • Best practices for database design ... • Combines the talkers, sentence and sentenceProduction table and only](https://reader034.vdocuments.site/reader034/viewer/2022050411/5f87f749a74a634c6c685615/html5/thumbnails/5.jpg)
![Page 6: RELATIONAL DATABASES - Northwestern University · 2013-01-30 · • Best practices for database design ... • Combines the talkers, sentence and sentenceProduction table and only](https://reader034.vdocuments.site/reader034/viewer/2022050411/5f87f749a74a634c6c685615/html5/thumbnails/6.jpg)
![Page 7: RELATIONAL DATABASES - Northwestern University · 2013-01-30 · • Best practices for database design ... • Combines the talkers, sentence and sentenceProduction table and only](https://reader034.vdocuments.site/reader034/viewer/2022050411/5f87f749a74a634c6c685615/html5/thumbnails/7.jpg)
![Page 8: RELATIONAL DATABASES - Northwestern University · 2013-01-30 · • Best practices for database design ... • Combines the talkers, sentence and sentenceProduction table and only](https://reader034.vdocuments.site/reader034/viewer/2022050411/5f87f749a74a634c6c685615/html5/thumbnails/8.jpg)
One size does not fit all
![Page 9: RELATIONAL DATABASES - Northwestern University · 2013-01-30 · • Best practices for database design ... • Combines the talkers, sentence and sentenceProduction table and only](https://reader034.vdocuments.site/reader034/viewer/2022050411/5f87f749a74a634c6c685615/html5/thumbnails/9.jpg)
Outline • Why use a relational database • Best practices for database design • Working with a relational database (MySQL and
phpMyAdmin)
![Page 10: RELATIONAL DATABASES - Northwestern University · 2013-01-30 · • Best practices for database design ... • Combines the talkers, sentence and sentenceProduction table and only](https://reader034.vdocuments.site/reader034/viewer/2022050411/5f87f749a74a634c6c685615/html5/thumbnails/10.jpg)
Example Data • Talkers
• Sentences • Acoustic analysis on sentences spoken by talkers
![Page 11: RELATIONAL DATABASES - Northwestern University · 2013-01-30 · • Best practices for database design ... • Combines the talkers, sentence and sentenceProduction table and only](https://reader034.vdocuments.site/reader034/viewer/2022050411/5f87f749a74a634c6c685615/html5/thumbnails/11.jpg)
“Flat Database” design
![Page 12: RELATIONAL DATABASES - Northwestern University · 2013-01-30 · • Best practices for database design ... • Combines the talkers, sentence and sentenceProduction table and only](https://reader034.vdocuments.site/reader034/viewer/2022050411/5f87f749a74a634c6c685615/html5/thumbnails/12.jpg)
![Page 13: RELATIONAL DATABASES - Northwestern University · 2013-01-30 · • Best practices for database design ... • Combines the talkers, sentence and sentenceProduction table and only](https://reader034.vdocuments.site/reader034/viewer/2022050411/5f87f749a74a634c6c685615/html5/thumbnails/13.jpg)
![Page 14: RELATIONAL DATABASES - Northwestern University · 2013-01-30 · • Best practices for database design ... • Combines the talkers, sentence and sentenceProduction table and only](https://reader034.vdocuments.site/reader034/viewer/2022050411/5f87f749a74a634c6c685615/html5/thumbnails/14.jpg)
“Column Heavy” design
![Page 15: RELATIONAL DATABASES - Northwestern University · 2013-01-30 · • Best practices for database design ... • Combines the talkers, sentence and sentenceProduction table and only](https://reader034.vdocuments.site/reader034/viewer/2022050411/5f87f749a74a634c6c685615/html5/thumbnails/15.jpg)
Flat vs. Relational
![Page 16: RELATIONAL DATABASES - Northwestern University · 2013-01-30 · • Best practices for database design ... • Combines the talkers, sentence and sentenceProduction table and only](https://reader034.vdocuments.site/reader034/viewer/2022050411/5f87f749a74a634c6c685615/html5/thumbnails/16.jpg)
![Page 17: RELATIONAL DATABASES - Northwestern University · 2013-01-30 · • Best practices for database design ... • Combines the talkers, sentence and sentenceProduction table and only](https://reader034.vdocuments.site/reader034/viewer/2022050411/5f87f749a74a634c6c685615/html5/thumbnails/17.jpg)
![Page 18: RELATIONAL DATABASES - Northwestern University · 2013-01-30 · • Best practices for database design ... • Combines the talkers, sentence and sentenceProduction table and only](https://reader034.vdocuments.site/reader034/viewer/2022050411/5f87f749a74a634c6c685615/html5/thumbnails/18.jpg)
![Page 19: RELATIONAL DATABASES - Northwestern University · 2013-01-30 · • Best practices for database design ... • Combines the talkers, sentence and sentenceProduction table and only](https://reader034.vdocuments.site/reader034/viewer/2022050411/5f87f749a74a634c6c685615/html5/thumbnails/19.jpg)
![Page 20: RELATIONAL DATABASES - Northwestern University · 2013-01-30 · • Best practices for database design ... • Combines the talkers, sentence and sentenceProduction table and only](https://reader034.vdocuments.site/reader034/viewer/2022050411/5f87f749a74a634c6c685615/html5/thumbnails/20.jpg)
![Page 21: RELATIONAL DATABASES - Northwestern University · 2013-01-30 · • Best practices for database design ... • Combines the talkers, sentence and sentenceProduction table and only](https://reader034.vdocuments.site/reader034/viewer/2022050411/5f87f749a74a634c6c685615/html5/thumbnails/21.jpg)
Flat vs. Relational
![Page 22: RELATIONAL DATABASES - Northwestern University · 2013-01-30 · • Best practices for database design ... • Combines the talkers, sentence and sentenceProduction table and only](https://reader034.vdocuments.site/reader034/viewer/2022050411/5f87f749a74a634c6c685615/html5/thumbnails/22.jpg)
Outline • Why use a relational database • Best practices for database design • Working with a relational database (MySQL and
phpMyAdmin)
![Page 23: RELATIONAL DATABASES - Northwestern University · 2013-01-30 · • Best practices for database design ... • Combines the talkers, sentence and sentenceProduction table and only](https://reader034.vdocuments.site/reader034/viewer/2022050411/5f87f749a74a634c6c685615/html5/thumbnails/23.jpg)
Basic query • SELECT [columns] FROM [table] WHERE [filters]
• SELECT * FROM `talker` WHERE 1 • (show all talkers)
• SELECT * FROM `talker` WHERE `age`>=20 • (get all talkers who are 25 or older)
• SELECT `talkerCode` FROM `talker` WHERE `age`>=20 • (same as above but only retrieves the talkerCode column)
![Page 24: RELATIONAL DATABASES - Northwestern University · 2013-01-30 · • Best practices for database design ... • Combines the talkers, sentence and sentenceProduction table and only](https://reader034.vdocuments.site/reader034/viewer/2022050411/5f87f749a74a634c6c685615/html5/thumbnails/24.jpg)
Combining tables • SELECT [columns] FROM [table1],[table2] WHERE [joins]
AND [filters]
• SELECT * FROM `talker`, `sentenceProduction` WHERE `sentenceProduction`.`talker_id` = `talker`.`talker_id` • Combines the talkers and sentenceProduction table
• SELECT * FROM `sentence`, `sentenceProduction` WHERE `sentenceProduction`.`sentence_id` = `sentence`.`sentence_id` • (Combine sentence and sentenceProduction table)
![Page 25: RELATIONAL DATABASES - Northwestern University · 2013-01-30 · • Best practices for database design ... • Combines the talkers, sentence and sentenceProduction table and only](https://reader034.vdocuments.site/reader034/viewer/2022050411/5f87f749a74a634c6c685615/html5/thumbnails/25.jpg)
Combining tables SELECT * FROM `talker`, `sentenceProduction` WHERE `sentenceProduction`.`talker_id` = `talker`.`talker_id` AND `talker`.`age` >=20
• Combines the talkers and sentenceProduction table and only get talkers who are 25 or older
![Page 26: RELATIONAL DATABASES - Northwestern University · 2013-01-30 · • Best practices for database design ... • Combines the talkers, sentence and sentenceProduction table and only](https://reader034.vdocuments.site/reader034/viewer/2022050411/5f87f749a74a634c6c685615/html5/thumbnails/26.jpg)
Combining tables SELECT * FROM `talker`, `sentence`, `sentenceProduction` WHERE `sentenceProduction`.`talker_id` = `talker`.`talker_id` AND `sentenceProduction`.`sentence_id`= `sentence`.`sentence_id`
• Combines the talkers, sentence and sentenceProduction table
![Page 27: RELATIONAL DATABASES - Northwestern University · 2013-01-30 · • Best practices for database design ... • Combines the talkers, sentence and sentenceProduction table and only](https://reader034.vdocuments.site/reader034/viewer/2022050411/5f87f749a74a634c6c685615/html5/thumbnails/27.jpg)
Combining tables SELECT `talker`.`talkerCode`, `talker`.`age` FROM `talker`, `sentence`, `sentenceProduction` WHERE `sentenceProduction`.`talker_id` = `talker`.`talker_id` AND `sentenceProduction`.`sentence_id`= `sentence`.`sentence_id`
• Combines the talkers, sentence and sentenceProduction table and only retrieves the talkerCode and age columns from the talker table
![Page 28: RELATIONAL DATABASES - Northwestern University · 2013-01-30 · • Best practices for database design ... • Combines the talkers, sentence and sentenceProduction table and only](https://reader034.vdocuments.site/reader034/viewer/2022050411/5f87f749a74a634c6c685615/html5/thumbnails/28.jpg)
Complex example SELECT `talker`.`talkerCode` , AVG( `sentenceProduction`.`totalDuration` ) AS `avg` , COUNT( * ) AS `number of sentences` FROM `talker` , `sentence` , `sentenceProduction` WHERE `sentenceProduction`.`talker_id` = `talker`.`talker_id` AND `sentenceProduction`.`sentence_id` = `sentence`.`sentence_id` GROUP BY `talker`.`talker_id`
![Page 29: RELATIONAL DATABASES - Northwestern University · 2013-01-30 · • Best practices for database design ... • Combines the talkers, sentence and sentenceProduction table and only](https://reader034.vdocuments.site/reader034/viewer/2022050411/5f87f749a74a634c6c685615/html5/thumbnails/29.jpg)
Extra stuff • MySQL + php allows for more complex queries when
necessary • To try this on your own computer, download and install
XAMPP (http://www.apachefriends.org/en/xampp.html)