text
stringlengths
1
81
start
float64
0
10.1k
duration
float64
0
24.9
that we can't delete Unidentified artist, because it's
3,062.48
3.03
referenced in the created table.
3,065.51
1.92
What we should maybe first do is delete this row delete their affiliation
3,067.43
4.8
with their work, and then delete the artist so we don't
3,072.23
3.87
run into this FOREIGN KEY constraint.
3,076.1
2.8
So let's try this in our SQLite environment.
3,078.9
3.62
Come back to my computer.
3,082.52
2.26
And again, our plan was to first delete the artists affiliation with their work
3,084.78
5.54
from the created table.
3,090.32
1.89
So let me show you first the created table.
3,092.21
2.25
I'll say SELECT [? star ?] from "created,"
3,094.46
3.78
and see how it's exactly like the table we just visualized.
3,098.24
3.84
Now, let me try delete this artist affiliation with their work.
3,102.08
4.74
I'm not deleting the artist.
3,106.82
2.05
I'm deleting their affiliation with their authorship,
3,108.87
3.41
their [? artist ?] [? ship, ?] whatever you want to call it for their work.
3,112.28
3.43
Now, I'll say DELETE FROM--
3,115.71
4.1
let's say, DELETE FROM "artists" WHERE the "artist_id" is equal to
3,119.81
7.5
or equals 3.
3,127.31
3.29
Well, I could do this.
3,130.6
2.17
But there's probably a better way, like I know the id, and that's fine.
3,132.77
4.07
But we could also use, as we saw a little bit ago,
3,136.84
2.53
which were [? subqueries, ?] a way to write a query that
3,139.37
3.14
returns me the result. And that result gets included in another query
3,142.51
3.45
altogether.
3,145.96
0.88
So let's try that instead.
3,146.84
1.43
Let's say I don't know the artist_id.
3,148.27
2.76
What I could do is make a [? subquery. ?]
3,151.03
2.1
I could say inside of this, let me select the "id" FROM the "artists"
3,153.13
6.3
table WHERE, in this case, the "name" equals "Unidentified artist," and then,
3,159.43
9.12
let me close out this query, hit a semicolon.
3,168.55
2.58
And I already see a typo in this, but I'm just going to try it anyway.
3,171.13
3.21
I will go ahead, and hit Enter.
3,174.34
2.7
And let's see if I type SELECT [? star ?] FROM "artists," Enter,
3,177.04
6.66
I still see Unidentified artist.
3,183.7
2.85
And I think my typo here was as follows.
3,186.55
1.93
If I up my query using the up arrow on my keyboard,
3,188.48
2.57
I see DELETE from "artists," where the "artist_id" equals some value here.
3,191.05
5.25
But do I want to delete from artists?
3,196.3
2.97
I don't.
3,199.27
0.72
I actually can't delete from artists.
3,199.99
1.62
What I should do instead is delete from the created table.
3,201.61
3.73
So let's try this.
3,205.34
1.01
I'll say DELETE FROM "created," making sure I only
3,206.35
4.29
have double quotes around created, then I'll
3,210.64
2.73
say WHERE the artist_id equals, let's say, either 3--
3,213.37
5.1
but it could also be the result of this [? subquery. ?]
3,218.47
3.06
I'll say 1, 2, 3, 4, and then SELECT the "id"
3,221.53
5.88
FROM the "artist" table WHERE the "name" equals "Unidentified artist."
3,227.41
8.47
Then I'll close this [? subquery, ?] hitting semicolon, hit Enter.
3,235.88
4.35
And now, if I say SELECT [? star ?] FROM "created" semicolon,
3,240.23
5.52
I should see that this artist's affiliation with their work
3,245.75
3.75
no longer exists.
3,249.5
2.1
And because it no longer exists.
3,251.6
1.51
I can now delete them from the artists table.
3,253.11
2.88
I don't have this FOREIGN KEY artist_id referencing
3,255.99
4.22
the primary key of this artist.
3,260.21
2.31
So let's now try that.
3,262.52
1.38
I could say SELECT [? star ?] FROM "artists,"
3,263.9
3.06
I see that Unidentified artist is still in here.
3,266.96
3.69
But let's delete them now.
3,270.65
1.86
I'll say delete from, let's say, "artists" WHERE
3,272.51
3.78
the "name" equals "Unidentified artist," closing my quotes, semicolon, hit
3,276.29
6.33
Enter.
3,282.62
0.66
And now if I Select [? star ?] FROM "artists" semicolon,
3,283.28
4.5
I should see they're no longer in this table to our earlier example.
3,287.78
4.74
This becomes a 2-step process.
3,292.52
2.23
First delete their affiliation, then delete their name.
3,294.75
4.73
OK, So let's try this yet again, but now using some additional tools
3,299.48
8.43
that we have at our disposal.
3,307.91
2.23
So let's look back at this FOREIGN KEY constraint that existed in this table.
3,310.14
6.72
If you remember, it looked a bit like this.
3,316.86
2.36
In my created table, I had this line.
3,319.22
2.76
FOREIGN KEY, artist_id, REFERENCES the "id" column in "artists."
3,321.98
6.24
Well, if that is the case, I can't delete the artist with the id
3,328.22
6.21
referenced by this [? foreign ?] [? key. ?] But it turns out that I
3,334.43
4.74
could specify some alternative action that happens when I try to delete
3,339.17
5.22
the id that is referenced by this [? foreign ?] [? key. ?] I can specify
3,344.39
4.2
that using a keyword called ON DELETE.
3,348.59
3.45
So after FOREIGN KEY REFERENCES [? "artist id," ?] I could say
3,352.04
2.82
afterwards ON DELETE, and then specify some action I want to actually happen
3,354.86
4.74
when I tried to delete the primary key referenced by this [? foreign ?]
3,359.6
3.9
[? key. ?]
3,363.5
0.93
One thing I could use would be RESTRICT, which
3,364.43
3.57
is kind of like what we saw before.
3,368
1.98
If I try to delete a primary key is [? referenced ?] by this [? foreign ?]
3,369.98
4.62
[? key, ?] I will not be allowed to do it.
3,374.6
2.49
That action is restricted.
3,377.09
2.63
I could also decide to take NO ACTION.
3,379.72
3.69
In this case, I could delete the primary key [? referenced ?] by this
3,383.41
4.74
[? foreign ?] [? key, ?] and nothing would happen.
3,388.15
2.41
I would actually be allowed to do that, which may be unwise in some cases,
3,390.56
4.73
but I could give myself that power.
3,395.29
2.76
I could also decide to SET NULL.
3,398.05
3.54
That is if I delete the primary key that is [? referenced ?] by this
3,401.59
4.74
[? foreign ?] [? key, ?] what I'll do is set the [? foreign ?] [? key ?] to be
3,406.33
3.36
NULL, meaning that value no longer exists.
3,409.69
3.967
I can alternatively [? set ?] it to a [? default ?] value for that column.
3,413.657
3.083
Or perhaps, most compellingly, I could try to CASCADE the deletion.
3,416.74
6.03
Where CASCADE means if I delete the artist, for instance,
3,422.77
3.82