text
stringlengths
1
81
start
float64
0
10.1k
duration
float64
0
24.9
so we could update it there.
3,800.69
3.23
But somehow, we need to cascade it over to the [? artists ?] [INAUDIBLE] now
3,803.92
4.92
this unidentified [? artist ?] [? through-- ?] I think we probably
3,808.84
3.54
don't need it.
3,812.38
0.727
SPEAKER 1: Yeah, so a good point here.
3,813.107
1.583
We could actually probably change the created table to [? re-associate ?]
3,814.69
4.56
an artist with some new artwork here.
3,819.25
2.5
So let's visualize this.
3,821.75
1.13
I go to my created table.
3,822.88
1.66
And here the artist_id is currently 3, but I want it really to be 1.
3,824.54
6.47
I want Li Yin to be associated with this piece called "Farmers working at dawn."
3,831.01
4.86
So I could update the created table to instead of having 3 here have 1.
3,835.87
5.73
Now, we see Li Yin created "Farmers working at dawn." [? And if ?]
3,841.6
4.62
you're concerned about this Unidentified artist here,
3,846.22
2.61
I think it's OK to have an artist in our table
3,848.83
2.55
who may or may not have an item in collections.
3,851.38
2.97
We'll say that's OK at least for now.
3,854.35
2.89
So if we can update our associations between artists and collections
3,857.24
5.03
like this, let's actually try to do that in our very own database here.
3,862.27
4.5
I'll go back to my SQLite environment, and now, let me try to open it first.
3,866.77
6.24
I'll use sqlite3 mfa.db.
3,873.01
2.55
And now let me type .schema to show you [INAUDIBLE] the very same schema from
3,875.56
3.9
before.
3,879.46
0.79
So I want to update the artists association between Li Yin and "Farmers
3,880.25
5.09
working at dawn."
3,885.34
1.23
So let's say, I'll SELECT [? star ?] FROM "created," like this, semicolon.
3,886.57
4.8
Here, I have my artist_ids and my collection_ids.
3,891.37
4.62
I see that we have the Unidentified artist, id of 3,
3,895.99
4.35
creating "Farmers working at dawn," with the id of 1 in our collection here.
3,900.34
5.35
So now, let's try to update the artist who created this particular painting.
3,905.69
5.48
Here, I have 3 associated with 1, but I want 1 associated with 1,
3,911.17
5.49
where 1 is the id for Li Yin.
3,916.66
1.92
And [? 1 ?] [? in ?] my collection id is the id for this artwork here.
3,918.58
4.278
So let me try this.
3,922.858
0.792
I'll say UPDATE "created" and SET, let's say, "artist_id"
3,923.65
5.97
equal to some particular value.
3,929.62
3.15
Well, what value should I set it to?
3,932.77
2.88
I could try to set it to Li Yin's id, which we know is just 1.
3,935.65
4.29
But let me try instead to use a [? subquery ?] here.
3,939.94
3.36
Let me try to say parentheses, and then write some query to update this value.
3,943.3
5.82
I'll say SELECT "id" from "artists" like this Enter again,
3,949.12
6.18
WHERE the "name" equals Li Yin.
3,955.3
4.89
And then let me close this [? subquery. ?] Well,
3,960.19
3.9
if I try to run this query, what might Happen I'm updating the created table,
3,964.09
6.42
I'm setting the artist_id equal to the id for Li Yin, but what I've forgotten
3,970.51
6.09
is this WHERE to only choose some rows to update.
3,976.6
4.92
[INAUDIBLE] not close it yet.
3,981.52
1.68
I'll instead say WHERE, in this case, the "collection_id," the piece
3,983.2
5.94
of artwork in our collection, is equal to [? while ?] the id
3,989.14
4.98
for this painting.
3,994.12
1.21
I'll say SELECT "id" from "collections," and then I'll
3,995.33
3.77
say WHERE the "title" equals "Farmers working at dawn."
3,999.1
6.61
Now, I'll close this [? subquery, ?] and hit semicolon.
4,005.71
3.99
And here, we've seen our first example of an UPDATE query.
4,009.7
3.9
I'm trying to update the artist_id column
4,013.6
2.91
in created to be the id for Li Yin.
4,016.51
3.48
I only want to do that though on the row where
4,019.99
3.06
collection_id is equal to the id for this particular painting.
4,023.05
4.41
[INAUDIBLE] change the attribution for.
4,027.46
2.01
So now, I'll hit Enter.
4,029.47
1.89
And if I SELECT [? star ?] FROM "created,"
4,031.36
3.01
I should hopefully see in this case that the artist_id associated
4,034.37
5.9
with this painting is 2 and also down below here is 1 as well.
4,040.27
5.41
So I have Li Yin associated with now two paintings overall.
4,045.68
5.61
So let's get a grasp on what this [? UPDATE ?] syntax really
4,051.29
3.47
looks like in general.
4,054.76
1.38
And for that, let's show the slide here.
4,056.14
2.58
We have this [? UPDATE ?] [? keyword, ?] [? UPDATE ?] statement in SQL to take
4,058.72
5.37
a table name and update the columns inside of it.
4,064.09
3.42
I say UPDATE, then the name of the table I want to update,
4,067.51
3.9
then I say SET some column equal to some value.
4,071.41
5.4
I could if I wanted to have more than one column here.
4,076.81
3.1
I could say maybe title and even maybe if we're
4,079.91
3.71
talking about authors, authors over here, or even acquired date.
4,083.62
3.42
I could update more than one column in my [? SET ?] [? portion ?] here.
4,087.04
4.89
Then comes this WHERE portion, where some condition is true.
4,091.93
4.44
I want to make sure I don't update all of my rows.
4,096.37
3.6
I only update those where some condition is actually true.
4,099.97
4.3
So this is your syntax for updating some columns.
4,104.27
3.799
Let's say, if you want to change an artist's attribution
4,108.069
2.79
or if you want to change a typo you've made.
4,110.859
4.091
So let's see this now, not just in terms of changing
4,114.95
3.86
artists and their attributions, let's see a use case for update
4,118.81
3.584
where we've made some mistakes in our data.
4,122.394
2.906
And let's say the museum decides to host some kind of event
4,125.3
4.309
where people vote on their favorite piece of artwork,
4,129.609
2.551
they kind of [? handwrite ?] or type it into some online form.
4,132.16
2.76
Well, when I get back, a CSV of those responses,
4,134.92
3.09
some Comma Separated Values, one line for each vote from our people
4,138.01
4.59
who've attended this convention.
4,142.6
2.04
Let's go back over here, and I'll show you that CSV.
4,144.64
3.839
Let me go to my environment.
4,148.479
2.581
And I'll type code mfa.csv to open this CSV that I already have.
4,151.06
5.879
And here, actually, it's not called mfa.csv.
4,156.939
2.491
It's called code votes.csv.
4,159.43
3
And now here we can see, I have a table of one column
4,162.43
5.46
that has several votes inside of it.
4,167.89
1.98
Let's see, we have maybe 20 votes to be exact.
4,169.87
3.27
So the first row is the header row.
4,173.14
2.7
I have in this CSV, one column called title.
4,175.84
3.809