relational databases - northwestern universitygroups.linguistics.northwestern.edu/speech_comm... ·...
TRANSCRIPT
RELATIONAL DATABASES SCRG Lab Group Demo, 23 Jan 2012
Outline • Why use a relational database • Best practices for database design • Working with a relational database (MySQL and
phpMyAdmin)
Outline • Why use a relational database • Best practices for database design • Working with a relational database (MySQL and
phpMyAdmin)
A systematic framework for storing and managing data
One size does not fit all
Outline • Why use a relational database • Best practices for database design • Working with a relational database (MySQL and
phpMyAdmin)
Example Data • Talkers
• Sentences • Acoustic analysis on sentences spoken by talkers
“Flat Database” design
“Column Heavy” design
Flat vs. Relational
Flat vs. Relational
Outline • Why use a relational database • Best practices for database design • Working with a relational database (MySQL and
phpMyAdmin)
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)
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)
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
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
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
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`
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)