text stringlengths 1 81 | start float64 0 10.1k | duration float64 0 24.9 |
|---|---|---|
let's also delete their affiliation
with their artwork all in one go. | 3,426.59 | 5 |
This converts our 2-step
process into a 1-step process. | 3,431.59 | 4.84 |
So let's visualize this. | 3,436.43 | 2.28 |
Let's say we have now applied
this constraint ON DELETE CASCADE. | 3,438.71 | 5.33 |
So if I delete the artist, I'll
also delete their affiliation | 3,444.04 | 3.81 |
with their work. | 3,447.85 | 1.26 |
We'll have the same two tables-- | 3,449.11 | 1.5 |
artists, collections, and created. | 3,450.61 | 3 |
Now again, artist_id references
this primary key in artists. | 3,453.61 | 5.82 |
Now, I'm going to try. | 3,459.43 | 1.08 |
I want to delete
Unidentified artist here. | 3,460.51 | 3.04 |
Well, I could do that. | 3,463.55 | 0.96 |
I could just delete their row. | 3,464.51 | 1.43 |
And now, instead of a FOREIGN
KEY constraint error, what I get | 3,465.94 | 4.5 |
is the following. | 3,470.44 | 1.05 |
[INAUDIBLE] [? created ?]
that this row is also gone. | 3,471.49 | 4.2 |
The row that had the
artist_id of 3 gets removed. | 3,475.69 | 4.27 |
We've cascaded the deletion
onward to the created table. | 3,479.96 | 5 |
So let's try this now with
a new database schema. | 3,484.96 | 3.8 |
I'll go back to my computer here. | 3,488.76 | 1.83 |
So I'm back in my [? TERMINAL ?] here. | 3,494.497 | 1.583 |
And I can type sqlite3 mfa.db
to reopen this database. | 3,496.08 | 5.1 |
And notice how if I type .schema, I've
updated this schema to now have ON | 3,501.18 | 4.98 |
DELETE CASCADE. | 3,506.16 | 0.99 |
Let me show you over here on the screen. | 3,507.15 | 1.98 |
Here on the created table, I now have
the very same kind of table schema, | 3,509.13 | 5.16 |
but now my only difference is
I've applied this ON DELETE action | 3,514.29 | 4.32 |
to my [? foreign ?]
[? key ?] constraints. | 3,518.61 | 1.95 |
In particular, I'm going
to [? cascade ?] the delete | 3,520.56 | 2.31 |
from the artist's table
to the created table. | 3,522.87 | 3.7 |
So let's try that out in SQLite. | 3,526.57 | 2.54 |
I'll come back over here,
and I will now try just | 3,529.11 | 3.66 |
DELETE FROM the "artists" table WHERE
the "name" equals "Unidentified artist. | 3,532.77 | 8.67 |
semicolon. | 3,541.44 | 0.99 |
Now, I'll hit Enter, and I don't get
a FOREIGN KEY constraint anymore. | 3,542.43 | 5.85 |
But if I say SELECT [? star ?]
FROM "created" semicolon, | 3,548.28 | 4.5 |
notice how I've also deleted the
artist's affiliation with their work. | 3,552.78 | 5.35 |
So that is wherever in
the artist_id column, | 3,558.13 | 3.83 |
I saw the id for the artist I
deleted, I would to delete that row, | 3,561.96 | 5.98 |
so I have no references to that primary
key, which is now gone from my table. | 3,567.94 | 6.35 |
So let me ask here. | 3,574.29 | 2.05 |
We've seen how to delete single
rows, how to delete multiple rows, | 3,576.34 | 5.27 |
and now how to delete data
among some constraints, | 3,581.61 | 2.985 |
like our [? foreign ?]
[? key ?] constraints. | 3,584.595 | 1.875 |
What questions do we
have on those techniques? | 3,586.47 | 5.16 |
Let's go to [? Han. ?] | 3,591.63 | 1.02 |
SPEAKER 13: I have a
question regarding deleting. | 3,592.65 | 3.09 |
The [? id ?] numbers have been removed
while we were removing the record. | 3,595.74 | 5.55 |
I was wondering if do we
have to clean it up somehow | 3,601.29 | 2.61 |
later or will they be populated
with the new data as it comes along? | 3,603.9 | 4.017 |
SPEAKER 1: Yeah, great question. | 3,607.917 | 1.333 |
So the question is, what happens to our
primary keys when we delete our data. | 3,609.25 | 4.44 |
So for this one, let
me show you the visual | 3,613.69 | 2.21 |
again that we had before of our
tables nicely printed on the side. | 3,615.9 | 3.78 |
So I'll come back here, and I will go
back to our idea of these joint tables | 3,619.68 | 7.11 |
where we had an artists table, a
collections table, and a created table. | 3,626.79 | 4.65 |
And we saw before that
we're going to delete | 3,631.44 | 1.89 |
this artist called Unidentified artist. | 3,633.33 | 2.67 |
So I'll delete them, and to your
point, [? well ?] the idea of 3 | 3,636 | 4.29 |
no longer exists in this case. | 3,640.29 | 3.12 |
Now by default, at least in SQLite,
if I insert a new row, what I'll do | 3,643.41 | 6.69 |
is take the highest id
value and I will then | 3,650.1 | 3.84 |
make that the new primary key
for the new row that I insert. | 3,653.94 | 4.5 |
That is the default situation. | 3,658.44 | 2.7 |
I could if I wanted
to get more specific, | 3,661.14 | 3.03 |
and if I had done in my id integer
column here in my [? create ?] | 3,664.17 | 7.38 |
[? table, ?] if I had also said
this [? keyword ?] [? call ?] | 3,671.55 | 3.15 |
[? autoincrement, ?] all one word,
what would happen instead is I would | 3,674.7 | 4.98 |
actually reinsert an
ID that is not used. | 3,679.68 | 4.03 |
So in this case 3 is not used,
I could insert that one here. | 3,683.71 | 4.38 |
So up to you what you want to do. | 3,688.09 | 2.27 |
In general, SQlite by default will take
the highest ID, add one from there. | 3,690.36 | 5.31 |
If you specify this constraint
[? called ?] [? autoincrement, ?] you | 3,695.67 | 3.27 |
will instead take whatever id is not
being used and use that in your insert | 3,698.94 | 5.37 |
afterwards. | 3,704.31 | 2.15 |
OK, so now we've seen how to
insert, and how to delete data. | 3,706.46 | 5.07 |
But of course, we make mistakes when we
add data or even when we delete data. | 3,711.53 | 4.03 |
So we'll see in just a minute
how to update our values | 3,715.56 | 3.02 |
as well to correct typos and
even to update associations | 3,718.58 | 3.33 |
between artists and artwork. | 3,721.91 | 2.88 |
And we're back. | 3,724.79 | 1.72 |
So we've so far seen how to
insert some data into our tables | 3,726.51 | 3.74 |
and how to delete it. | 3,730.25 | 1.83 |
But sometimes, we don't want
to fully delete something, | 3,732.08 | 3.39 |
we just want to change its
value to correct some typo | 3,735.47 | 3.03 |
or correct some association. | 3,738.5 | 1.98 |
So let's think to our MFA example,
[? where ?] the Museum of Fine Arts | 3,740.48 | 4.47 |
has some tables that look like this. | 3,744.95 | 2.32 |
They have artists in their
collection, and they also | 3,747.27 | 2.78 |
have art work in their collection. | 3,750.05 | 2.13 |
They also have a created table to
associate artists with their artwork. | 3,752.18 | 4.77 |
Now in this case, we know that
I have this Unidentified artist. | 3,756.95 | 6.24 |
And we can see that they authored
this item in the collections, | 3,763.19 | 4.23 |
"Farmers working at dawn." | 3,767.42 | 2.58 |
But let's say that later on, we find
out it wasn't an Unidentified artist. | 3,770 | 5.73 |
It was instead Li Yin, who
created "Farmers working at dawn." | 3,775.73 | 4.29 |
How could we update our tables to
make sure it's Li Yin, who we have | 3,780.02 | 6.33 |
creating "Farmers working at dawn." | 3,786.35 | 4.31 |
SPEAKER 14: So what we could do is-- | 3,790.66 | 4.494 |
we know that in created, we have our
artist_id and [? collection id, ?] | 3,795.154 | 5.536 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.