text stringlengths 1 81 | start float64 0 10.1k | duration float64 0 24.9 |
|---|---|---|
I now see I'm down to two paintings,
two pieces of artwork that | 2,705.87 | 4.95 |
were acquired only after 1909. | 2,710.82 | 4.9 |
OK, so given this part on DELETE, we're
able to delete one row or even multiple | 2,715.72 | 7.47 |
rows at a time. | 2,723.19 | 1.125 |
But there are still
instances where you might | 2,724.315 | 1.875 |
want to think about, should we delete
something or can we delete something. | 2,726.19 | 4.89 |
We'll talk about those in just a
minute in terms of constraints. | 2,731.08 | 3.93 |
We back in a few. | 2,735.01 | 1.17 |
And we're back. | 2,736.18 | 1.68 |
So we just saw how to delete
one row, even multiple rows. | 2,737.86 | 5.4 |
We haven't yet talked about
whether we should delete some data | 2,743.26 | 3.36 |
or whether we should delete
some data and particularly | 2,746.62 | 2.4 |
in the context of these
constraints, where | 2,749.02 | 2.16 |
you might have maybe a
piece of data you actually | 2,751.18 | 2.16 |
shouldn't delete to maintain
the integrity of your table. | 2,753.34 | 4.12 |
Now, one example of this is
a [? Foreign ?] [? Key ?] | 2,757.46 | 3.41 |
[? Constraint, ?] which means that you
have some table with a primary key that | 2,760.87 | 5.01 |
is referenced by some other table. | 2,765.88 | 2.283 |
And we'll get concrete
about this in a minute. | 2,768.163 | 1.917 |
But it might mean that if you
were to delete that primary key, | 2,770.08 | 3.3 |
that other table would
have nothing to reference. | 2,773.38 | 2.83 |
So let's update our schema here for
the MFA, the Museum of Fine Arts. | 2,776.21 | 4.4 |
And let's say that they have not just
a collection now, but also artists | 2,780.61 | 4.53 |
involved. | 2,785.14 | 0.75 |
And there exists a [? many ?] [? to ?]
[? many ?] relationship among artists | 2,785.89 | 4.08 |
and items in the collection. | 2,789.97 | 2.19 |
We could say that an artist might
make more than one piece of art | 2,792.16 | 4.32 |
in the collection. | 2,796.48 | 1.23 |
And a piece of art might be
created by more than one artist. | 2,797.71 | 4.77 |
Now concretely in our database,
this might look as follows. | 2,802.48 | 4.57 |
I could have a table for artists
and a table for collections. | 2,807.05 | 4.43 |
And notice how each has
their own primary key. | 2,811.48 | 3.3 |
Artists has an id column,
called our primary key column. | 2,814.78 | 3.33 |
Collections too has an id called
our primary key column here. | 2,818.11 | 4.29 |
Now, in the middle is this
table created that symbolizes, | 2,822.4 | 4.02 |
that represents the relationship among
artists and items in the collection. | 2,826.42 | 4.86 |
Here on the first row, we see the
artist id of 1 created the piece of art | 2,831.28 | 5.1 |
with the collection id of 2. | 2,836.38 | 2.37 |
So who did what here? | 2,838.75 | 2.08 |
Well, we can see that the artist
with the ID of 1 is Li Yin. | 2,840.83 | 4.37 |
Li Yin created this piece of art, the
id of 2, which is Imaginative landscape. | 2,845.2 | 6.54 |
So we can kind of relate in this
case artists with collections | 2,851.74 | 3.6 |
as we saw just a few weeks ago. | 2,855.34 | 2.55 |
But let's say we decide to
delete a particular artist, | 2,857.89 | 3.99 |
maybe we delete Unidentified
artists down here. | 2,861.88 | 3.63 |
Well, we could just delete
from the artist table. | 2,865.51 | 2.59 |
Maybe we find a condition to select
this row and we delete from artists. | 2,868.1 | 5.84 |
We'll do that here remove that row. | 2,873.94 | 2.67 |
But what have we done wrong? | 2,876.61 | 2.91 |
If we look at our created
table in particular, | 2,879.52 | 4.04 |
what have we now done wrong? | 2,883.56 | 2.79 |
What kind of problem might we [? run ?]
[? into? ?] Let's go to [? Karim. ?] | 2,886.35 | 7.51 |
SPEAKER 11: [? Yeah ?] [INAUDIBLE]
[? was ?] [? only ?] [? deleted ?] | 2,893.86 | 3.455 |
[? from ?] [? the ?] [? artist ?]
[INAUDIBLE] without the other | 2,897.315 | 2.625 |
[INAUDIBLE]. | 2,899.94 | 0.813 |
SPEAKER 1: Yeah, good point. | 2,900.753 | 1.167 |
We only deleted the artist with
the id of 3 from the artists table. | 2,901.92 | 5.73 |
Now if I look at the created table and
I look for the artist with id of 3, | 2,907.65 | 6.693 |
do you see them? | 2,914.343 | 0.667 |
They don't exist anymore. | 2,915.01 | 1.18 |
So I can't understand this relationship. | 2,916.19 | 2 |
I don't know the artist
with the id of 3. | 2,918.19 | 3.93 |
So let's try this now with a new
kind of schema now in our database. | 2,922.12 | 5.67 |
I'll go back to my computer. | 2,927.79 | 2.49 |
And let me open up our new
version of our database. | 2,930.28 | 3.57 |
I'll type sqlite3, in this case, mfa.db,
same name, but now a different schema. | 2,933.85 | 7.59 |
If I type .schema,
notice a few things here. | 2,941.44 | 4.2 |
I have those same
tables we saw visually. | 2,945.64 | 3.45 |
I have collections, artists,
and a created table. | 2,949.09 | 4.65 |
And [? let me ?] focus in
particular on this created table. | 2,953.74 | 2.94 |
If I say .schema, in this
case, created, Enter, | 2,956.68 | 4.41 |
I'll see I have a FOREIGN KEY
constraint on my "artist_id" | 2,961.09 | 5.52 |
column and my "collection_id" column. | 2,966.61 | 3.43 |
So if I tried to delete an artist that
is referenced in my created table, | 2,970.04 | 6.26 |
I would probably raise
a constraint error-- | 2,976.3 | 3.69 |
a FOREIGN KEY [? constraint ?] error. | 2,979.99 | 2.38 |
So let's just try this
and see what happens. | 2,982.37 | 3.3 |
Let me try DELETE FROM the
[? artist's ?] [? table, ?] DELETE FROM | 2,985.67 | 4.88 |
"artists" WHERE, let's say the "name"
of the artist is literally "Unidentified | 2,990.55 | 8.51 |
artist." | 2,999.06 | 0.88 |
This is the name they have in the
Museum of Fine Arts collections-- | 2,999.94 | 3.62 |
Unidentified artist. | 3,003.56 | 1.71 |
So now I want to delete
them from that table. | 3,005.27 | 3 |
Well, if I hit Enter, I do get
that FOREIGN KEY constraint error. | 3,008.27 | 5.86 |
So does this mean I just can't delete
this artist or is there a workaround? | 3,014.13 | 5.48 |
Let's look at it visually again. | 3,019.61 | 1.68 |
I'll go back to what we
had before as our table, | 3,021.29 | 3.45 |
and let me ask the audience here. | 3,024.74 | 2.88 |
What's the solution? | 3,027.62 | 1.59 |
If I can't delete Unidentified
artist, because they | 3,029.21 | 3.93 |
have an id referenced by this
table, what should I maybe do first? | 3,033.14 | 5.16 |
What should I do instead? | 3,038.3 | 1.395 |
SPEAKER 12: Yeah, I want
to say that first we | 3,039.695 | 1.875 |
can delete the id that is being
referenced by this [? id ?] | 3,041.57 | 4.59 |
that we want to delete,
then we can delete it. | 3,046.16 | 2.58 |
In fact, if we want to
delete it from the artists, | 3,048.74 | 2.43 |
first we have to delete from the
created table [INAUDIBLE] table, which | 3,051.17 | 3.78 |
it is referencing, then we can
delete from the artist [INAUDIBLE] | 3,054.95 | 3.12 |
SPEAKER 1: Yeah, I like
your thinking here. | 3,058.07 | 1.99 |
So if we look at the
created table, you notice | 3,060.06 | 2.42 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.