text
stringlengths
1
81
start
float64
0
10.1k
duration
float64
0
24.9
You can add a default, which just adds a default value to a particular column.
710.14
4.65
Primary Key we've seen.
714.79
1.26
Unique guarantees that every value is going to be unique.
716.05
3.18
So if you don't want to allow for the same value
719.23
2.61
to appear twice for a particular column, you
721.84
2.417
can add a unique constraint to a particular column
724.257
2.083
to enforce that as well.
726.34
1.86
Check can be used to make sure that a value obeys a certain condition.
728.2
3.96
Like, a number falls within a certain range, for example.
732.16
2.738
If you have movie ratings, for example, and you're storing movie ratings inside
734.898
3.292
of a database, you might care to make sure
738.19
1.8
that those ratings are within the 1 to 5 range or the 1 to 10 range
739.99
3.9
or whatever range you deem valid for the database.
743.89
3.3
So via constraints you can begin to ensure
747.19
2.31
that as you add data to the table, that data is going to be valid in some way.
749.5
3.96
That it needs to obey and certain constraints,
753.46
2.67
otherwise, if you try to add it to the table,
756.13
2.11
it's not going to be accepted at all.
758.24
2.66
And so that leads into the natural next question, which
760.9
2.4
is, I now have all of these various different tables
763.3
2.64
that I can create using these create table commands,
765.94
2.49
but how do I actually add data into those tables?
768.43
3.24
The way we're going to do that is via an INSERT command, where we're
771.67
3.36
going to insert data into a SQL table.
775.03
3.36
So what might that command look like?
778.39
1.62
The command is generally going to look like this.
780.01
2.64
We're going to say, INSERT Into, to say I
782.65
2.49
would like to add a new row into a table.
785.14
3.03
Following that, we provide the name of the table.
788.17
2.07
Something like "flight" to say, I would like
790.24
1.833
to add a new row to the flights table.
792.073
2.577
And following the name of the table, we need
794.65
2.01
to provide in parentheses a comma-separated list
796.66
3.24
of all of the column names for which we are going to provide values.
799.9
4.93
So here I said I want to provide values for the origin, destination,
804.83
3.84
and duration of this flight.
808.67
2.06
Note that I'm leaving out the ID column.
810.73
1.8
I don't have to worry about adding a value for the ID,
812.53
2.588
because I said the id should autoincrement.
815.118
1.792
So it's going to automatically give the next available ID.
816.91
3.54
And what values am I going to provide?
820.45
1.89
Well, after the word "values", I provide, again,
822.34
2.56
in parentheses, a comma-separated list of all of the values
824.9
3.77
that are to be associated with those columns in the same order.
828.67
3.3
So origin was the first one here.
831.97
1.9
So origin will correspond to New York.
833.87
1.94
Destination will correspond to London.
835.81
2.04
Duration will correspond to 415.
837.85
3.06
So this query let's me take the flights table that I've already created
840.91
3.84
and add some data into that table.
844.75
4.26
So you can use these INSERT queries once you
849.01
2.28
have a table to being able to add new rows of data to that table.
851.29
3.18
Every time a new flight comes up for an airline,
854.47
2.31
the airline might, behind the scenes, be running an INSERT
856.78
2.79
into Flights command that takes data about that flight
859.57
3.24
and adds it to the table.
862.81
1.53
But, of course, once we've added data to a table,
864.34
2.58
we'd ideally like some way to get data out of that table, as well.
866.92
3.86
That once we've stored data inside of our database
870.78
2.44
we want to retrieve that data, too.
873.22
2.13
To do that, we're going to use a particular type of query
875.35
2.94
called a SELECT query.
878.29
1.47
What SELECT is going to do is take a table that already exists
879.76
3.93
and allow us to get data out of that table.
883.69
2.992
It's not going to modify the data that's there,
886.682
1.958
it's just going to retrieve data that might be inside a particular table.
888.64
3.702
So what do those queries look like?
892.342
1.458
Well, the simplest query might look a little something like this.
893.8
2.708
SELECT * from flights.
896.508
2.632
SELECT from flights means I want to select data from the flights table.
899.14
4.44
And this * is a wild card that here just means
903.58
3.42
select all of the possible columns that you can.
907
2.56
So if this is my table, my table of flights
910.06
1.86
where each flight has an id, an origin, a destination, and a duration,
911.92
5.05
then select * from flights will select all of that data.
916.97
3.12
All of the rows and all of the columns are
920.09
2.22
going to come back to me when I run a query like this.
922.31
3.638
Now it's possible that when I'm running these queries, when I'm accessing data,
925.948
3.292
that I don't actually care about all of these columns,
929.24
2.398
especially if I have a table with many more columns than just this.
931.638
2.792
Maybe I only care about particular columns.
934.43
2.73
And it would be wasteful to query the database
937.16
2.01
asking it to return to me a whole lot more data than I actually need.
939.17
4.06
So instead I could run query like this.
943.23
2.66
SELECT-- instead of * I'm saying select origin comma destination from flights.
945.89
6.42
So I'm again selecting from the flights table.
952.31
1.93
Selecting all of the rows still, but the difference
954.24
3.26
is that instead of select *, which means select all of the columns that
957.5
3.69
are present in the table, select origin comma destination means I'm only
961.19
4.2
going to select these two columns--
965.39
1.98
the origin column and the destination column.
967.37
2.52
So highlighted in blue here is the data that
969.89
2.28
would be returned if someone were to run this particular SQL query.
972.17
4.65
Now especially as tables begin to get larger and begin to have more and more
976.82
3.45
rows-- here I just have six rows, but you might imagine a table with
980.27
3.12
thousands or even millions of rows within it--
983.39
2.43
you probably don't want to be returning every single row every single time.
985.82
4.09
So just as you can constrain which columns come back to you,
989.91
2.79
likewise, you too can constrain which rows come back
992.7
2.54
to you when you perform a query.
995.24
2.07