relational databases - northwestern universitygroups.linguistics.northwestern.edu/speech_comm... ·...

29
RELATIONAL DATABASES SCRG Lab Group Demo, 23 Jan 2012

Upload: others

Post on 03-Jun-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: RELATIONAL DATABASES - Northwestern Universitygroups.linguistics.northwestern.edu/speech_comm... · SCRG Lab Group Demo, 23 Jan 2012 . Outline • Why use a relational database •

RELATIONAL DATABASES SCRG Lab Group Demo, 23 Jan 2012

Page 2: RELATIONAL DATABASES - Northwestern Universitygroups.linguistics.northwestern.edu/speech_comm... · SCRG Lab Group Demo, 23 Jan 2012 . Outline • Why use a relational database •

Outline • Why use a relational database • Best practices for database design • Working with a relational database (MySQL and

phpMyAdmin)

Page 3: RELATIONAL DATABASES - Northwestern Universitygroups.linguistics.northwestern.edu/speech_comm... · SCRG Lab Group Demo, 23 Jan 2012 . Outline • Why use a relational database •

Outline • Why use a relational database • Best practices for database design • Working with a relational database (MySQL and

phpMyAdmin)

Page 4: RELATIONAL DATABASES - Northwestern Universitygroups.linguistics.northwestern.edu/speech_comm... · SCRG Lab Group Demo, 23 Jan 2012 . Outline • Why use a relational database •

A systematic framework for storing and managing data

Page 5: RELATIONAL DATABASES - Northwestern Universitygroups.linguistics.northwestern.edu/speech_comm... · SCRG Lab Group Demo, 23 Jan 2012 . Outline • Why use a relational database •
Page 6: RELATIONAL DATABASES - Northwestern Universitygroups.linguistics.northwestern.edu/speech_comm... · SCRG Lab Group Demo, 23 Jan 2012 . Outline • Why use a relational database •
Page 7: RELATIONAL DATABASES - Northwestern Universitygroups.linguistics.northwestern.edu/speech_comm... · SCRG Lab Group Demo, 23 Jan 2012 . Outline • Why use a relational database •
Page 8: RELATIONAL DATABASES - Northwestern Universitygroups.linguistics.northwestern.edu/speech_comm... · SCRG Lab Group Demo, 23 Jan 2012 . Outline • Why use a relational database •

One size does not fit all

Page 9: RELATIONAL DATABASES - Northwestern Universitygroups.linguistics.northwestern.edu/speech_comm... · SCRG Lab Group Demo, 23 Jan 2012 . Outline • Why use a relational database •

Outline • Why use a relational database • Best practices for database design • Working with a relational database (MySQL and

phpMyAdmin)

Page 10: RELATIONAL DATABASES - Northwestern Universitygroups.linguistics.northwestern.edu/speech_comm... · SCRG Lab Group Demo, 23 Jan 2012 . Outline • Why use a relational database •

Example Data • Talkers

• Sentences • Acoustic analysis on sentences spoken by talkers

Page 11: RELATIONAL DATABASES - Northwestern Universitygroups.linguistics.northwestern.edu/speech_comm... · SCRG Lab Group Demo, 23 Jan 2012 . Outline • Why use a relational database •

“Flat Database” design

Page 12: RELATIONAL DATABASES - Northwestern Universitygroups.linguistics.northwestern.edu/speech_comm... · SCRG Lab Group Demo, 23 Jan 2012 . Outline • Why use a relational database •
Page 13: RELATIONAL DATABASES - Northwestern Universitygroups.linguistics.northwestern.edu/speech_comm... · SCRG Lab Group Demo, 23 Jan 2012 . Outline • Why use a relational database •
Page 14: RELATIONAL DATABASES - Northwestern Universitygroups.linguistics.northwestern.edu/speech_comm... · SCRG Lab Group Demo, 23 Jan 2012 . Outline • Why use a relational database •

“Column Heavy” design

Page 15: RELATIONAL DATABASES - Northwestern Universitygroups.linguistics.northwestern.edu/speech_comm... · SCRG Lab Group Demo, 23 Jan 2012 . Outline • Why use a relational database •

Flat vs. Relational

Page 16: RELATIONAL DATABASES - Northwestern Universitygroups.linguistics.northwestern.edu/speech_comm... · SCRG Lab Group Demo, 23 Jan 2012 . Outline • Why use a relational database •
Page 17: RELATIONAL DATABASES - Northwestern Universitygroups.linguistics.northwestern.edu/speech_comm... · SCRG Lab Group Demo, 23 Jan 2012 . Outline • Why use a relational database •
Page 18: RELATIONAL DATABASES - Northwestern Universitygroups.linguistics.northwestern.edu/speech_comm... · SCRG Lab Group Demo, 23 Jan 2012 . Outline • Why use a relational database •
Page 19: RELATIONAL DATABASES - Northwestern Universitygroups.linguistics.northwestern.edu/speech_comm... · SCRG Lab Group Demo, 23 Jan 2012 . Outline • Why use a relational database •
Page 20: RELATIONAL DATABASES - Northwestern Universitygroups.linguistics.northwestern.edu/speech_comm... · SCRG Lab Group Demo, 23 Jan 2012 . Outline • Why use a relational database •
Page 21: RELATIONAL DATABASES - Northwestern Universitygroups.linguistics.northwestern.edu/speech_comm... · SCRG Lab Group Demo, 23 Jan 2012 . Outline • Why use a relational database •

Flat vs. Relational

Page 22: RELATIONAL DATABASES - Northwestern Universitygroups.linguistics.northwestern.edu/speech_comm... · SCRG Lab Group Demo, 23 Jan 2012 . Outline • Why use a relational database •

Outline • Why use a relational database • Best practices for database design • Working with a relational database (MySQL and

phpMyAdmin)

Page 23: RELATIONAL DATABASES - Northwestern Universitygroups.linguistics.northwestern.edu/speech_comm... · SCRG Lab Group Demo, 23 Jan 2012 . Outline • Why use a relational database •

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 Universitygroups.linguistics.northwestern.edu/speech_comm... · SCRG Lab Group Demo, 23 Jan 2012 . Outline • Why use a relational database •

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 Universitygroups.linguistics.northwestern.edu/speech_comm... · SCRG Lab Group Demo, 23 Jan 2012 . Outline • Why use a relational database •

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 Universitygroups.linguistics.northwestern.edu/speech_comm... · SCRG Lab Group Demo, 23 Jan 2012 . Outline • Why use a relational database •

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 Universitygroups.linguistics.northwestern.edu/speech_comm... · SCRG Lab Group Demo, 23 Jan 2012 . Outline • Why use a relational database •

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 Universitygroups.linguistics.northwestern.edu/speech_comm... · SCRG Lab Group Demo, 23 Jan 2012 . Outline • Why use a relational database •

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 Universitygroups.linguistics.northwestern.edu/speech_comm... · SCRG Lab Group Demo, 23 Jan 2012 . Outline • Why use a relational database •

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)