Skip to content

Commit

Permalink
Updated slides for week 1.
Browse files Browse the repository at this point in the history
Added many-to-many relationship.
  • Loading branch information
Frank Versnel committed Feb 4, 2018
1 parent 3005433 commit 3d251cd
Show file tree
Hide file tree
Showing 4 changed files with 163 additions and 1 deletion.
1 change: 1 addition & 0 deletions Week1/.vscode/database.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
42 changes: 42 additions & 0 deletions Week1/databases/musicians2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
DROP database IF EXISTS hyf_musicians2;
CREATE database hyf_musicians2;
USE hyf_musicians2;

CREATE TABLE Musicians(
Id INT NOT NULL,
FirstName TEXT NOT NULL,
LastName TEXT NOT NULL,
Born INT NOT NULL,
PRIMARY KEY (Id)
);

CREATE TABLE Instruments(
Id INT NOT NULL,
Name TEXT NOT NULL,
Type TEXT NOT NULL,
PRIMARY KEY (Id)
);

CREATE TABLE InstrumentsPlayed(
Id INT NOT NULL,
Musician INT NOT NULL,
Instrument INT NOT NULL,
PRIMARY KEY (Id),
FOREIGN KEY (Musician) REFERENCES Musicians(Id),
FOREIGN KEY (Instrument) REFERENCES Instruments(Id)
);

INSERT INTO Musicians (Id, FirstName, LastName, Born) VALUES (1, 'Thelonious', 'Monk', 1917);
INSERT INTO Musicians (Id, FirstName, LastName, Born) VALUES (2, 'Sonny', 'Rollins', 1930);
INSERT INTO Musicians (Id, FirstName, LastName, Born) VALUES (3, 'Steve', 'Lehman', 1978);

INSERT INTO Instruments (Id, FirstName, LastName, Born) VALUES (1, 'Piano', 'Keys');
INSERT INTO Instruments (Id, FirstName, LastName, Born) VALUES (2, 'Tenor saxophone', 'Wind');
INSERT INTO Instruments (Id, FirstName, LastName, Born) VALUES (3, 'Soprano saxophone', 'Wind');
INSERT INTO Instruments (Id, FirstName, LastName, Born) VALUES (4, 'Alto saxophone', 'Wind');
INSERT INTO Instruments (Id, FirstName, LastName, Born) VALUES (5, 'Guitar', 'String');

INSERT INTO InstrumentsPlayed (Id, Musician, Instrument) VALUES (1, 1, 1);
INSERT INTO InstrumentsPlayed (Id, Musician, Instrument) VALUES (2, 2, 2);
INSERT INTO InstrumentsPlayed (Id, Musician, Instrument) VALUES (3, 2, 3);
INSERT INTO InstrumentsPlayed (Id, Musician, Instrument) VALUES (3, 3, 4);
121 changes: 120 additions & 1 deletion Week1/slides/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@

`programming`: **object**

*what or who the subject relates to*
*who or what the subject relates to*

---

Expand Down Expand Up @@ -291,6 +291,8 @@

# Identity

![Thelonious Monk](media/thelonious-monk.jpg)

---

# Identity: identifying a subject
Expand Down Expand Up @@ -528,6 +530,123 @@
1 row in set (0.00 sec)
```

---

class: center, middle

# More relationships

---

# Many-to-many relationship

How do we model which instruments the muscians played?

<table class="db-table">
<tr>
<th>Musicians</th>
</tr>
<tr>
<th>Id</th>
<th>FirstName</th>
<th>LastName</th>
<th>Born</th>
</tr>
<tr>
<td>1</td>
<td>Thelonious</td>
<td>Monk</td>
<td>1917</td>
</tr>
<tr>
<td>2</td>
<td>Sonny</td>
<td>Rollins</td>
<td>1930</td>
</tr>
<tr>
<td>3</td>
<td>Steve</td>
<td>Lehman</td>
<td>1978</td>
</tr>
</table>

<br/>

<table class="db-table">
<tr>
<th>Instruments</th>
</tr>
<tr>
<th>Id</th>
<th>Name</th>
<th>Type</th>
</tr>
<tr>
<td>1</td>
<td>Piano</td>
<td>Key</td>
</tr>
<tr>
<td>2</td>
<td>Tenor Saxophone</td>
<td>Wind</td>
</tr>
<tr>
<td>3</td>
<td>Soprano Saxophone</td>
<td>Wind</td>
</tr>
<tr>
<td>4</td>
<td>Alto-saxophone</td>
<td>Wind</td>
</tr>
<tr>
<td>5</td>
<td>Guitar</td>
<td>String</td>
</tr>
</table>

---

class: center, middle

# Answer: with another table!

<table class="db-table">
<tr>
<th>InstrumentsPlayed</th>
</tr>
<tr>
<th>Id</th>
<th>Musician</th>
<th>Instrument</th>
</tr>
<tr>
<td>1</td>
<td>1</td>
<td>1</td>
</tr>
<tr>
<td>2</td>
<td>2</td>
<td>2</td>
</tr>
<tr>
<td>2</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>3</td>
<td>3</td>
<td>4</td>
</tr>
</table>

</textarea>
<script src="js/remark.js">
</script>
Expand Down
Binary file added Week1/slides/media/thelonious-monk.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3d251cd

Please sign in to comment.