text stringlengths 1 81 | start float64 0 10.1k | duration float64 0 24.9 |
|---|---|---|
And there are tradeoffs there, too. | 428.84 | 2.175 |
Then there are various
different types of integers. | 431.015 | 2.125 |
There's not just a single integer type. | 433.14 | 1.92 |
But SMALLINT and INT and BIGINT, each
of which uses a different number of | 435.06 | 3.65 |
bytes in order to store an integer data. | 438.71 | 2.29 |
So if you want to be able to store
much larger or much smaller numbers, | 441 | 3.17 |
you might need a bigger type,
like an INT or a BIGINT. | 444.17 | 2.278 |
But if your numbers are
going to be pretty small, | 446.448 | 2.042 |
maybe you're OK with just a SMALLINT. | 448.49 | 2 |
And likewise there are similar types of
trade-offs for floating point numbers. | 450.49 | 3.25 |
Where, much as in programming
languages like C, if you're familiar, | 453.74 | 2.792 |
have both a float and a double type. | 456.532 | 1.888 |
Where a double uses more bytes of
memory in order to store information. | 458.42 | 3.66 |
Here, too, we have FLOAT
and DOUBLE, which allow | 462.08 | 2.7 |
us to store floating point numbers. | 464.78 | 1.63 |
Numbers that might be real numbered
values, where a double just | 466.41 | 2.99 |
allows us to express a number
to a little bit more precision | 469.4 | 3.06 |
than a floating point
number might be able to. | 472.46 | 2.07 |
And there are many other types
as well, but the general idea | 474.53 | 2.5 |
is that here even in SQL,
much as in a language | 477.03 | 2.3 |
like Python, we have types for each of
these various different kinds of data. | 479.33 | 4.66 |
So now that we understand that each type
of data has types, what we'd like to do | 483.99 | 3.65 |
is to be able to, inside of a
database, actually create a table. | 487.64 | 3.777 |
And there are various
different SQL commands | 491.417 | 1.833 |
that we can run on our
database in order to perform | 493.25 | 2.58 |
various different operations. | 495.83 | 1.59 |
And the first we might
want to execute is | 497.42 | 1.83 |
a command that is just going
to create a table, for example. | 499.25 | 3.28 |
So how might we go about doing that? | 502.53 | 1.62 |
Well, it turns out the
syntax for creating | 504.15 | 1.75 |
a table is going to look a
little something like this. | 505.9 | 2.56 |
This here is the syntax we would
use to create a table in SQLite | 508.46 | 4.17 |
for representing flights, for example. | 512.63 | 2.789 |
So we begin with the
keyword Create Table, | 515.419 | 2.88 |
to say I would like to create a
new table inside of this database. | 518.299 | 3.63 |
Next I give the name of the table. | 521.929 | 1.921 |
Every table has a name
just for ease of reference. | 523.85 | 2.43 |
And here the name and the table
is just the word "flights." | 526.28 | 3.6 |
Then what follows in parentheses
are a comma-separated list | 529.88 | 3.87 |
of all of the columns that
should be present in the table. | 533.75 | 3.09 |
I'm not yet adding
any data to the table. | 536.84 | 2.22 |
The Create Table query is just going
to decide the structure of the table. | 539.06 | 3.79 |
What are the columns and
what are the columns' types. | 542.85 | 3.1 |
And so here we see that
in the beginning of each | 545.95 | 2.32 |
of these clauses that are separated by
commas, we have the name of the column. | 548.27 | 5.62 |
So we have an id column because, though
we didn't see this before, often in SQL | 553.89 | 4.13 |
it's going to be helpful
to be able to have | 558.02 | 1.89 |
some way of uniquely referencing a
particular element inside of the table. | 559.91 | 3.902 |
Maybe there are multiple
flights that are | 563.812 | 1.708 |
going from New York to
London, for example, | 565.52 | 3.45 |
and I want some way of
distinguishing between them. | 568.97 | 2.31 |
And one easy way is to give every
single entry inside of a table | 571.28 | 3.93 |
a unique identifier, or a unique id,
represented here by this id column. | 575.21 | 4.827 |
And that's going to be a way of
making sure that we can always | 580.037 | 2.583 |
access a particular flight uniquely. | 582.62 | 2.94 |
So we have an id column, an origin
column, a destination column, | 585.56 | 3.27 |
and a duration column. | 588.83 | 1.65 |
Each of those columns has a type. | 590.48 | 2.79 |
So the types here, id is an integer. | 593.27 | 2.01 |
It's just going to be some number
representing the flight, counting one, | 595.28 | 3 |
two, three, four, and
so on and so forth. | 598.28 | 2.22 |
Origin and destination
we'll label here as text. | 600.5 | 2.87 |
Though you'll see that
if we were using my SQL, | 603.37 | 2.65 |
I might make these a variable
length character that | 606.02 | 2.305 |
could be up to a certain
number of characters | 608.325 | 1.875 |
if I know there's
probably not going to be | 610.2 | 1.75 |
a city that's longer than a certain
number of characters, for instance. | 611.95 | 3.4 |
Then I have a duration,
which here is an integer. | 615.35 | 2.72 |
Some number of minutes
that is going to be | 618.07 | 1.83 |
how long it takes for this flight to
go from the origin to the destination. | 619.9 | 4.82 |
After the types for
each of the columns, I | 624.72 | 1.75 |
have additional constraints that I
might add to the columns as well. | 626.47 | 3.48 |
So integer Primary Key. | 629.95 | 1.98 |
The Primary Key here
means that the id is | 631.93 | 2.37 |
going to be the primary way via
which I uniquely identify a flight. | 634.3 | 4.02 |
There's going to be
some optimizations here | 638.32 | 1.8 |
to make it very quick to be able
to look up a flight by its id. | 640.12 | 4.26 |
Null is a constraint that I can
place on columns to be able to say, | 644.38 | 3.91 |
I don't want to allow for this
particular column to ever be empty. | 648.29 | 3.39 |
I don't want there to ever be a
flight that doesn't have an origin | 651.68 | 2.75 |
or doesn't have a
destination or a duration. | 654.43 | 2.38 |
So I can add constraints to
a particular column to say, | 656.81 | 3.65 |
the origin, destination,
duration, columns | 660.46 | 2.49 |
should not be allowed to be null. | 662.95 | 1.74 |
I want to always have an origin
and a destination and a duration. | 664.69 | 4.53 |
Finally this Autoincrement
after the Primary Key | 669.22 | 2.88 |
is a cue into SQL to automatically
update the id every time | 672.1 | 3.87 |
I add a new row into the table. | 675.97 | 1.612 |
So if I add a new flight,
I can give the flight | 677.582 | 1.958 |
an origin, destination, and duration. | 679.54 | 2.01 |
But I don't have to worry
about giving it an id. | 681.55 | 2.338 |
SQL is going to handle
that for me automatically. | 683.888 | 2.042 |
Automatically giving that new row
in that table the next available id | 685.93 | 6.75 |
number. | 692.68 | 1.05 |
Here, then, is the way we create a
table by giving the name of the table, | 693.73 | 3.3 |
each of the columns, the types
for each of those columns, | 697.03 | 2.91 |
and then any constraints we would
want to place on the columns. | 699.94 | 4.45 |
There are a number of
different types of constraints | 704.39 | 2.3 |
that I can add to a particular column. | 706.69 | 1.68 |
Not null is one we've seen before. | 708.37 | 1.77 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.