text
stringlengths 1
81
| start
float64 0
10.1k
| duration
float64 0
24.9
|
|---|---|---|
for each of these rows.
| 1,692.02
| 1.68
|
And more often than
not, you'll likely have
| 1,693.7
| 2.25
|
a database or CSV that looks a bit
more like this without the primary key.
| 1,695.95
| 4.92
|
But you'll still want to have a primary
key when you import into your database.
| 1,700.87
| 4.84
|
So let's try working
with this kind of CSV now
| 1,705.71
| 3.29
|
and having SQLite generate some
of the primary keys for us.
| 1,709
| 3.87
|
Come back to my computer.
| 1,712.87
| 1.86
|
And let's update our mfa.csv just to
remove those primary key column here.
| 1,714.73
| 5.71
|
So I will open up again mfa.csv.
| 1,720.44
| 4.46
|
And let me try to just delete
this column all together.
| 1,724.9
| 2.7
|
I'll move [? id, ?] remove 1,
and 2, and 3, and 4, and 5.
| 1,727.6
| 7.08
|
Let me save it, and now
that id column is gone.
| 1,734.68
| 4.57
|
But now there's a problem.
| 1,739.25
| 1.77
|
Like if I go to my schema,
and I type .schema,
| 1,741.02
| 4.53
|
notice how there are four
columns in this table--
| 1,745.55
| 3.75
|
"id," "title," "accession_number,"
and "acquired."
| 1,749.3
| 4.05
|
Well, now my CSV only has three columns.
| 1,753.35
| 3.64
|
So if I try to import
this CSV into this table,
| 1,756.99
| 3.53
|
I'm going to run into trouble, because
I have different numbers of columns
| 1,760.52
| 3.21
|
[? between ?] my CSV and my table.
| 1,763.73
| 3.025
|
Well, what can I do instead?
| 1,766.755
| 2.375
|
It turns out that I could
actually import this data
| 1,769.13
| 3.78
|
into a temporary table,
and then take that data
| 1,772.91
| 3.57
|
and insert that data in that
temporary table into my real one
| 1,776.48
| 3.57
|
called "collections" here.
| 1,780.05
| 1.62
|
I can use both .import and INSERT
INTO to accomplish that task for me.
| 1,781.67
| 6
|
So let's try this.
| 1,787.67
| 1.14
|
I'll say .import.
| 1,788.81
| 1.95
|
I want to import a CSV now-- [? dash ?]
[? dash ?] [? CSV. ?] Which one?
| 1,790.76
| 4.23
|
Well, mfa.csv in this case.
| 1,794.99
| 3.09
|
Now, though, I want to create a brand
new table that doesn't yet exist.
| 1,798.08
| 3.822
|
So I'll type the name of the table.
| 1,801.902
| 1.458
|
And I just call it temp for
now to temporarily import
| 1,803.36
| 3.54
|
this data into a brand new table.
| 1,806.9
| 2.49
|
And notice how here I'm not
using [? dash ?] [? dash ?]
| 1,809.39
| 2.87
|
skip 1, because now I want to take
advantage of those header rows.
| 1,812.26
| 4.09
|
SQLite, if I import into a new table,
will notice I have a header row
| 1,816.35
| 6.46
|
and make my columns the very same
names that are in my header row--
| 1,822.81
| 4.79
|
title, accession number, and acquired.
| 1,827.6
| 2.61
|
I don't want to skip them.
| 1,830.21
| 1.17
|
I want SQLite to see them and create
this table using those header rows.
| 1,831.38
| 5.23
|
So now, I'll hit Enter, and
nothing seems to happen.
| 1,836.61
| 3.38
|
But if I type .schema, what do I see,
but a brand new table called "temp"
| 1,839.99
| 5.01
|
that SQLite has just made automatically
and notice how it used that header row.
| 1,845
| 4.05
|
I have "title," "accession_number,"
and "acquired" as my column names.
| 1,849.05
| 5.745
|
OK, let's now look
inside the temp table,
| 1,854.795
| 2.585
|
I'll say SELECT [? star ?]
FROM "temp" semicolon.
| 1,857.38
| 5.14
|
And now, I see all that data in there.
| 1,862.52
| 1.83
|
But I don't have primary keys yet.
| 1,864.35
| 1.85
|
So my goal [? is ?] [? really ?]
to take all this data and insert it
| 1,866.2
| 3.87
|
into my collections table to give it
that primary key I've been wanting
| 1,870.07
| 4.56
|
here.
| 1,874.63
| 0.72
|
Again, if I type SELECT [? star ?]
FROM "collections," well, nothing-- oh,
| 1,875.35
| 5.648
|
something is still there.
| 1,880.998
| 1.042
|
Let me actually just
delete this [INAUDIBLE]
| 1,882.04
| 2.177
|
I'll say DELETE FROM "collections"
to remove it all together-- we'll
| 1,884.217
| 2.833
|
[? get ?] [INAUDIBLE] just a minute.
| 1,887.05
| 1.5
|
And now let me try, SELECT
[? star ?] FROM "collections,"
| 1,888.55
| 4.47
|
and I should see nothing
inside of collections.
| 1,893.02
| 3.73
|
So what could I do?
| 1,896.75
| 1.29
|
I could [? INSERT ?] [? INTO ?]
[? collections ?] using the data from
| 1,898.04
| 3.59
|
my temp table.
| 1,901.63
| 1.5
|
So I'll try that.
| 1,903.13
| 0.85
|
I'll say INSERT INTO "collections"
and choose those columns yet again.
| 1,903.98
| 5.48
|
I'll say the "title," and
the "accession_number,"
| 1,909.46
| 4.99
|
and now let's go for the
"acquired" column as well.
| 1,914.45
| 4.45
|
I'll hit Enter.
| 1,918.9
| 1.47
|
But instead of typing
many new lines of values,
| 1,920.37
| 3.96
|
I actually have a way to dynamically
select all the values I want to insert,
| 1,924.33
| 5.91
|
and it looks a bit like this.
| 1,930.24
| 1.93
|
I could say INSERT INTO [? some ?]
table and some columns of that table.
| 1,932.17
| 6.72
|
But I want to insert the results
of this SELECT down below.
| 1,938.89
| 4.44
|
So I'll [? SELECT ?] some columns
[? FROM ?] some separate table.
| 1,943.33
| 3.39
|
And so long as these columns align, I'll
be able to actually take the results
| 1,946.72
| 5.13
|
of that [? SELECT ?] and [? insert ?]
all of them [? into ?] this new table
| 1,951.85
| 3.33
|
using INSERT INTO.
| 1,955.18
| 1.89
|
So let me finish my statement
here, we can see the results.
| 1,957.07
| 2.85
|
Come back to my computer.
| 1,959.92
| 2.13
|
And here, I'll type a SELECT to get
back all the items from my temp table.
| 1,962.05
| 5.64
|
I'll say SELECT-- in
this case, SELECT, let's
| 1,967.69
| 4.38
|
go for the "title" column,
the "accession_number"
| 1,972.07
| 4.38
|
column, and the "acquired"
column from my "temp" table.
| 1,976.45
| 4.65
|
Now, if I hit semicolon, I should see--
| 1,981.1
| 4.17
|
well, nothing at first.
| 1,985.27
| 1.2
|
But if I type SELECT
[? star ?] FROM "collections,"
| 1,986.47
| 4.53
|
I see all my data now in there
selected from my temporary table.
| 1,991
| 5.61
|
And now if I type
.schema, I still see temp.
| 1,996.61
| 3.013
|
But what can I do now?
| 1,999.623
| 0.917
|
I could just delete
that table altogether.
| 2,000.54
| 2.17
|
I could say DROP TABLE "temp," as we
saw last week, semicolon, hit Enter,
| 2,002.71
| 5.66
|
.schema again.
| 2,008.37
| 1.72
|
And now, we're back where we
want to be with a single table,
| 2,010.09
| 3.59
|
and now we've import our data
from our CSV with primary keys.
| 2,013.68
| 5.35
|
If I type "collections" here,
we see it all in this table.
| 2,019.03
| 5.62
|
OK, so we've seen several
versions of import, one
| 2,024.65
| 3.54
|
to import into an existing table and
one to import into a brand new table.
| 2,028.19
| 4.27
|
Let me ask then what questions we have
on how to use .import or how to insert
| 2,032.46
| 6.08
|
more data into our database.
| 2,038.54
| 4.7
|
Let's go [? Louise. ?]
| 2,043.24
| 1.19
|
SPEAKER 6: Can we ask the
INSERT INTO command to place
| 2,044.43
| 3.9
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.