10
Lecture 17 MySQL Tables and Relations 101 * * Course logo spider web photograph from Morguefile openstock photograph by Gabor Karpati, Hungary.

Lecture 17 - Colorado State Universityct310/yr2017sp/more_progress/pdfs/ct... · Lecture 17 MySQL Tables and Relations 101 * * ... Leo Kottke Wizz Jones Altan John Fahey Mudlark Lucky

Embed Size (px)

Citation preview

Lecture 17MySQL

Tables and Relations 101

*

* Course logo spider web photograph from Morguefile openstock photograph by Gabor Karpati, Hungary.

3/7/17 Slide 2

Review – Starting Servers

3/7/17 Slide 2CSU CS CT 310 - Web Development, ©Ross Beveridge & Jamie Ruiz

Keep in mind MySQL works through a client-server interface to a separate database server process/machine.

Data - Tables

ØTable is, more or less, a flat database.

ØContains “things”, objects.ØOne thing per row.ØColumns store attributes.ØPrimary index unique for each row.ØRelations kick in later

ØHow we relate tables to one another.

3/7/17 Slide 3CSU CS CT 310 - Web Development, ©Ross Beveridge & Jamie Ruiz

Exercise Some Commands

Ø use

Ø CREATE

Ø INSERT

Ø SELECT

Ø UPDATE

Ø DROP

3/7/17 CSU CS CT 310 - Web Development, ©Ross Beveridge & Jamie Ruiz Slide 4

cd_id name artist

1 Mudlark Leo Kottke

2 My Feet Are Smiling Leo Kottke

3 Lucky The Man Wizz Jones

4 The Blue Idol Altan

5 Return of the Repressed John Fahey

3/7/17 Slide 5

Create Music Database

3/7/17 Slide 5CSU CS CT 310 - Web Development, ©Ross Beveridge & Jamie Ruiz

In general, new databases do not come and go often.

3/7/17 Slide 6

Example 1

3/7/17 Slide 6CSU CS CT 310 - Web Development, ©Ross Beveridge & Jamie Ruiz

Where’s the Beef, ah … Data.

Ø Data from tables is stored in files.Ø Case sensitivity comes from host OS.Ø In case it is not obvious.

Ø NEVER MANIPULATE THESE FILES DIRECTLY.

3/7/17CSU CS CT 310 - Web Development, ©Ross Beveridge & Jamie

Ruiz Lecture 18, Slide 7

Relations 101

ØLeo Kottke appears twice.

3/7/17 Slide 8CSU CS CT 310 - Web Development, ©Ross Beveridge & Jamie Ruiz

Leo Kottke Wizz Jones Altan John Fahey

Mudlark

Lucky The Man

Return of the Repressed

The Blue Idol

My Feet Are Smiling

3/7/17 Slide 9

Example 2

3/7/17 Slide 9CSU CS CT 310 - Web Development, ©Ross Beveridge & Jamie Ruiz

3/7/17 Slide 10

Keys: Primary and Foreign

3/7/17 Slide 10CSU CS CT 310 - Web Development, ©Ross Beveridge & Jamie Ruiz

Primary Key Unique!

Establishes Relation:Loosely speaking, a ‘pointer’ to the other

object.

Two cdsrelated to one artist.