text
stringlengths
1
81
start
float64
0
10.1k
duration
float64
0
24.9
Today, we'll learn how to actually add data to our databases--
31.6
2.85
to insert, to update, and delete data.
34.45
3.7
We'll do all of this in the context of Boston's very own Museum of Fine Arts,
38.15
5.18
or the MFA for short.
43.33
1.84
So the MFA here in Boston is a century--
45.17
2.447
well, maybe, about a century-old museum that
47.617
1.833
has many artifacts and artwork inside of it, both historical and contemporary.
49.45
5.19
And it's worth asking, how do they keep track of the thousands of items
54.64
4.08
that are in their collections?
58.72
1.69
What could they possibly use?
60.41
1.88
Well, chances are, they're likely using some kind of database.
62.29
4.29
And on that database, they want to do four actions
66.58
4.05
we've learned about back in week zero.
70.63
2.55
They could, perhaps, create data-- to add data or insert data to the database
73.18
4.44
when they get some new piece of artwork, for instance.
77.62
2.65
They might want to query the database, to read from it.
80.27
2.7
They could also update data, change the artist, change the artwork in some way.
82.97
4.28
And they could also just delete data to remove it all together.
87.25
4.09
But if we think about these--
91.34
1.58
creating, reading, updating, and deleting-- we'll
92.92
3.45
notice that reading, updating, and deleting-- we
96.37
2.67
can't do those if we don't actually have data in our database.
99.04
3.87
And so today, we'll see how to create data--
102.91
3.3
how to insert data into our very own database.
106.21
4.65
Now, let's think about the MFA's [? collections, ?] [? their ?]
110.86
3.54
[? collection ?] of art and artifacts.
114.4
1.583
And let me propose that they have a database [? that ?]
115.983
2.292
looks a bit like this.
118.275
1.265
It's a single table, and it has a title column and accession
119.54
4.16
number, which is a fancy way of saying a unique ID internal to the museum,
123.7
4.68
and also, a date it was acquired.
128.38
2.58
We have, of course, a primary key on this table called ID.
130.96
4.65
And let's think.
135.61
1.02
Well, the museum might want to acquire this piece here--
136.63
3.03
this one called Profusion of Flowers.
139.66
2.73
Well, how could they log that this artwork is inside of their database?
142.39
5.55
They could maybe just add a new row.
147.94
2.22
They could say, let's put Profusion of Flowers
150.16
2.13
as the first item in our collections here.
152.29
2.61
We'll give it a title and accession number-- which, again,
154.9
2.53
is just a unique ID internal to the museum--
157.43
2.67
and the date it was acquired.
160.1
2.15
And that row then has its own primary key
162.25
3.09
to identify this row uniquely in our database.
165.34
3.66
Now let's say they get another piece of artwork.
169
2.04
They get this one, called Farmers Working at Dawn,
171.04
3.09
and they want to add this one to their table, too.
174.13
2.323
Well, they could do the very same thing.
176.453
1.667
They could just add a new row.
178.12
1.26
They could say, let's make a title, an accession number,
179.38
2.55
and a date it was acquired, and this brand-new row
181.93
2.31
here for that piece of artwork.
184.24
2.43
And maybe they get another one, too.
186.67
2.16
Same thing.
188.83
0.78
Maybe they'll get back Spring Outing, and they
189.61
2.16
want to add this to their collection.
191.77
1.95
They could simply add another row like this.
193.72
4.09
Now, it turns out that the database administrator behind the MFA
197.81
4.25
might be running a SQL statement that looks a bit like this--
202.06
4.56
INSERT INTO.
206.62
2.25
We can use INSERT INTO to add a new row to any given table.
208.87
5.31
And notice how insert into needs to know a few pieces of information.
214.18
4.72
The first is what table to insert into.
218.9
3.65
What is the name of that table?
222.55
2.46
Second, it needs to know what columns are
225.01
2.7
we adding data to inside of this table?
227.71
3.42
We give it a list of those columns here.
231.13
2.25
Then, of course, it needs to know what new values should
233.38
3.75
go into this new row for each of these columns.
237.13
3.66
Like we saw before, is it Profusion of Flowers?
240.79
3.03
Is it Spring Outing?
243.82
1.38
Et cetera.
245.2
1.11
Here, we can see that we have this list of values.
246.31
3.07
And notice how value 0, the first value in this list,
249.38
3.23
corresponds to the new value that will be inserted [? to ?] this first column.
252.61
4.95
And we can keep having value 1, or column 1, value 2 and column 2,
257.56
3.899
each one aligning with that particular column there.
261.459
4.451
So let's see an example of this actually in code,
265.91
3.39
understand it a bit more concretely.
269.3
2.24
I'll go back to my computer here.
271.54
2.19
Let's actually create our very own database
273.73
2.34
that involves this schema of having our very own table which can keep artists
276.07
4.92
and artwork and artifacts as well.
280.99
3.64
So I'll type
284.63
0.77
1: [? TRANSCRIPT BREAK ?] So I'll type sqlite3 mfa.db
285.4
4.11
to create a database for the Museum of Fine Arts, abbreviated as MFA.
289.51
5.94
I'll hit Enter here.
295.45
1.24
And notice how I can now have access to my very own mfa.db inside my SQLite
296.69
6.62
environment.
303.31
1.08
Well, now, I can type .schema to see the schema of this database.
304.39
5.12
So if I hit Enter here, well, nothing's there.
309.51
2.973
Because I just made this database.
312.483
1.417
There's nothing in it yet.
313.9
2.1
Well, it turns out I do actually have a schema file prepared for me
316
3.84
already in schema.sql.
319.84
2.49
Here, I propose we make a table called "collections," and like our table
322.33
4.2
visually, it has let's say four columns.
326.53
2.79
One as an "id," the primary key of this table, one for a "title,"
329.32
6.195
one for the "accession_number," the unique ID internal to the museum,
335.515
4.095
and finally, the date it was acquired.
339.61
3.06