text stringlengths 1 81 | start float64 0 10.1k | duration float64 0 24.9 |
|---|---|---|
a column in a specific position? | 2,048.33 | 2.057 |
SPEAKER 1: Good question. | 2,050.387 | 1.042 |
Can we ask INSERT INTO the place
a column in a certain position? | 2,051.429 | 4.599 |
There's a few ways of getting [? it-- ?]
what I think you're asking here, | 2,056.028 | 3.042 |
so let me show you a few of those here. | 2,059.07 | 1.625 |
I'll come back to my computer, and let
me pull up the syntax for INSERT INTO | 2,060.695 | 5.694 |
again. | 2,066.389 | 0.821 |
I will choose this, and I'll
show it on the screen over here. | 2,067.21 | 4.59 |
So I'll say INSERT INTO some
table given some columns. | 2,071.8 | 4.609 |
And notice how down below,
I actually have [? values ?] | 2,076.409 | 2.73 |
to insert into those columns. | 2,079.139 | 2.461 |
I could, to your question,
rearrange these values. | 2,081.6 | 3.52 |
So I might have this first value here is
some value that goes into this column. | 2,085.12 | 4.55 |
The second column here is
attached to that column. | 2,089.67 | 2.489 |
And that would rearrange the
values I insert into those columns. | 2,092.159 | 3.841 |
If you're asking, though, if
I can reorder the columns, | 2,096 | 3.27 |
that is up to [? CREATE ?] [? TABLE ?]
and [? CREATE ?] [? TABLE ?] only. | 2,099.27 | 3.463 |
And in general, I encourage you not so
much out of ordering of your columns, | 2,102.733 | 3.167 |
[? because ?] [? it ?] could
be in any order whatsoever. | 2,105.9 | 2.333 |
But you could just rearrange
your selection of columns | 2,108.233 | 2.647 |
here to insert the data
you want to insert. | 2,110.88 | 3.9 |
OK, let's take one more question here. | 2,114.78 | 2.83 |
SPEAKER 7: What happens if one of
the rows you're trying to insert | 2,117.61 | 2.78 |
violates a constraint on the table? | 2,120.39 | 1.95 |
SPEAKER 1: Yeah, so here
we're inserting multiple rows. | 2,122.34 | 2.8 |
And if one actually
violates some constraint, | 2,125.14 | 3.29 |
then we won't actually
insert any of those rows. | 2,128.43 | 3.18 |
And this is because this
insert is bundled inside | 2,131.61 | 2.4 |
of a transaction, which we'll learn
more about later on in the course. | 2,134.01 | 4.63 |
Let's take another one. | 2,138.64 | 1.593 |
SPEAKER 8: I noticed that when you did
SELECT [? star ?] FROM "collections," | 2,140.233 | 3.167 |
that one of the acquired
dates was just blank. | 2,143.4 | 2.34 |
It didn't say NULL. | 2,145.74 | 1.29 |
Is that because the CSV itself just
had an empty value next to the comma? | 2,147.03 | 4.26 |
SPEAKER 1: Yeah, great observations. | 2,151.29 | 1.5 |
So let me try this again. | 2,152.79 | 1.06 |
So we can see the results
of this [? SELECT. ?] | 2,153.85 | 1.958 |
I'll come back to my computer
here, and let me show you again. | 2,155.808 | 4.212 |
If I say SELECT [? star ?]
FROM "collections" | 2,160.02 | 3.12 |
semicolon, notice how this acquired
column-- this acquired cell here, if I | 2,163.14 | 4.83 |
go back to my screen, it's just blank. | 2,167.97 | 3.36 |
But we saw before that if I
[? selected ?] [? star, ?] I would have | 2,171.33 | 3.39 |
seen [? NULL ?] there if this
value was truly [? NULL. ?] Well, | 2,174.72 | 4.74 |
it turns out one downside of importing
from a CSV is that all of your data is | 2,179.46 | 5.43 |
imported initially as text. | 2,184.89 | 2.34 |
And if I have just a
blank cell in my CSV, | 2,187.23 | 3.69 |
it won't be converted to
[? NULL ?] automatically. | 2,190.92 | 3.21 |
I need to do that myself
perhaps using an [? update ?] | 2,194.13 | 2.7 |
statement that we'll see in just a bit. | 2,196.83 | 1.96 |
So be wary of this if you do want to
keep track of [? null ?] [? values ?] | 2,198.79 | 3.35 |
and so on. | 2,202.14 | 0.79 |
If you don't actually manually
make this value a [? null, ?] | 2,202.93 | 3.14 |
it'll appear as just a
blank value not a null, | 2,206.07 | 3.16 |
which is different in this respect. | 2,209.23 | 3.54 |
OK so here, we've seen how to insert
not just one row, but multiple, | 2,212.77 | 5.61 |
and also how to import data from a CSV. | 2,218.38 | 3.46 |
When we come back, we'll see how to
actually update our data altogether, | 2,221.84 | 4.14 |
and even delete it too. | 2,225.98 | 1.295 |
So come back in just a
few and talk about how | 2,227.275 | 1.875 |
to delete data from our tables. | 2,229.15 | 1.8 |
And we're back. | 2,230.95 | 1.74 |
So we just saw how to insert
some rows into our database, | 2,232.69 | 3.85 |
and also to import some data. | 2,236.54 | 1.94 |
But presumably, we also want to be
able to delete some data from our table | 2,238.48 | 3.84 |
as well. | 2,242.32 | 0.97 |
You can imagine the MFA,
the Museum of Fine Arts, | 2,243.29 | 2.84 |
maybe they're selling a piece of
artwork, or maybe they've lost one, | 2,246.13 | 3.33 |
or maybe it was stolen. | 2,249.46 | 1.29 |
But either way, they want to
remove the row from their table. | 2,250.75 | 4.23 |
Well, let's see here. | 2,254.98 | 1.41 |
We can go back to our schema with
a table of artifacts and artwork | 2,256.39 | 4.71 |
that is inside of the MFA. | 2,261.1 | 2.52 |
Now if I want to delete
a particular piece, | 2,263.62 | 2.25 |
you could visually think
of it a bit like this. | 2,265.87 | 2.08 |
I could first identify
that row I want to delete. | 2,267.95 | 3.32 |
Let's say it's Spring outing here. | 2,271.27 | 1.71 |
We've sold this piece. | 2,272.98 | 1.83 |
Well, I could visually
just remove this row. | 2,274.81 | 3.4 |
So it's no longer there and shift
the remaining ones up metaphorically. | 2,278.21 | 4.25 |
And it turns out that
to do this in SQL, we | 2,282.46 | 3.15 |
have our very own statement we can use. | 2,285.61 | 2.61 |
This one reads DELETE FROM some
table WHERE a condition is true. | 2,288.22 | 6.61 |
So we see our old
friend WHERE back again. | 2,294.83 | 2.72 |
And WHERE is vitally
important to this DELETE FROM. | 2,297.55 | 3.06 |
If I say DELETE FROM
table with no WHERE, | 2,300.61 | 3.3 |
what do you think is going to happen? | 2,303.91 | 2.88 |
We might drop everything
from our table, right? | 2,306.79 | 3.06 |
But if I instead say WHERE
some condition is true, | 2,309.85 | 3.06 |
I can select the rows I want to
delete and only delete those rows. | 2,312.91 | 5.26 |
So let's try this here. | 2,318.17 | 1.73 |
I'll try to delete some artwork
from our collections table, | 2,319.9 | 3.18 |
for example, maybe we sold
it and we want get rid of it. | 2,323.08 | 2.53 |
I'll come back to my computer over here,
and I will open up our SQLite database. | 2,325.61 | 6.35 |
I'll say sqlite3 mfa.db. | 2,331.96 | 2.58 |
And now, I can type SELECT
[? star ?] [? FROM ?] "collections," | 2,334.54 | 3.75 |
and I see a few more items than last
time now all inside of our table. | 2,338.29 | 5.7 |
But per the visual, I want
to delete Spring outing, | 2,343.99 | 3.66 |
to remove it from this table. | 2,347.65 | 2.17 |
So what could I do? | 2,349.82 | 1.08 |
I could try DELETE FROM and then
the table I want to delete from. | 2,350.9 | 4.37 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.