WEBVTT

00:00.180 --> 00:02.520
OK so we're moving on in this video.

00:02.610 --> 00:05.190
We're talking about default values.

00:05.310 --> 00:07.160
What's up with this part right here.

00:07.350 --> 00:11.930
Default So as we talked about a little bit in the last video it's helpful to be able to decide or to

00:11.930 --> 00:13.590
set default values.

00:13.590 --> 00:18.340
So if something is not specified that there will be a fallback.

00:18.750 --> 00:20.220
And here's how we do it.

00:20.340 --> 00:22.690
We use default.

00:23.010 --> 00:28.190
So you can see both of these when we're defining a table default and then we specify a default.

00:28.260 --> 00:36.150
So for name if you leave off name I just said OK we'll call it unnamed or name to be determined sometimes

00:36.350 --> 00:42.780
if this is a cat shelter in the real world sometimes they decide on a name a little bit later once they

00:42.780 --> 00:48.180
figure out the cat's personality and then for age if this is more of a silly example but if we wanted

00:48.180 --> 00:52.830
to if you didn't specify age we could always set it to be ninety nine.

00:52.920 --> 00:57.070
Not sure why but for the sake of this exercise we're going to do it.

00:57.240 --> 00:58.490
So let's give it a shot.

00:58.650 --> 01:02.180
Remaking a new cats table cat 3.

01:03.210 --> 01:04.590
OK here we go.

01:04.630 --> 01:11.540
So create table cats 3 and I'll do a new line here.

01:13.560 --> 01:18.140
And we will have a name for our car.

01:18.180 --> 01:20.800
Let's do 20 even though my slides say 100.

01:20.830 --> 01:21.440
It's OK.

01:21.780 --> 01:25.690
Default in our default will be.

01:25.840 --> 01:29.240
That's a no name provided.

01:29.250 --> 01:30.750
How about that.

01:30.930 --> 01:36.690
It's important that whatever you put here matches the data type so we couldn't say the default is the

01:36.690 --> 01:38.860
number 100.

01:39.450 --> 01:47.130
And then we'll have our Khama age and age isn't it.

01:47.590 --> 01:54.790
Default should be 99 perfect clothes that.

01:55.110 --> 02:01.030
Now if we do our describe cats 3 Here we go.

02:01.380 --> 02:07.760
So we have default no provided default 99 for H.

02:07.800 --> 02:08.380
Awesome.

02:08.580 --> 02:18.700
OK so now let's give it a shot let's do insert into Cat 3 and I'll do.

02:19.380 --> 02:20.260
Age only.

02:20.280 --> 02:27.320
And no name and age will be let's do 13 just like that.

02:27.330 --> 02:34.170
What do you think will happen going to insert a new cat into Cat 3 which is right here only for fighting

02:34.200 --> 02:40.000
age and name has a default value of no name provided.

02:40.540 --> 02:41.640
Ok I did it.

02:41.650 --> 02:46.720
Now let's look like Star from Cat 3.

02:47.420 --> 02:49.760
And I get no name provided.

02:49.980 --> 02:50.670
Perfect.

02:50.670 --> 02:53.000
So we have a default value that's working great.

02:53.100 --> 02:55.080
We could do the same thing for age.

02:55.080 --> 03:00.330
Feel free to skip this if you feel like you know exactly what's going to happen.

03:00.330 --> 03:00.900
I'll leave.

03:00.930 --> 03:07.960
Let's leave both off this time and certain to catch three values.

03:08.450 --> 03:09.440
Now when we select.

03:09.650 --> 03:14.720
We have another unnamed cat this time who is ninety nine years old by default.

03:14.870 --> 03:21.830
So the next thing that I want to talk about here is another version of creating a table for cats for

03:21.890 --> 03:22.470
this time.

03:22.610 --> 03:26.820
And I combined not know all along side default.

03:26.990 --> 03:33.420
Otherwise it's the same so we have name our car default this unnamed age it default that's 99.

03:33.650 --> 03:36.040
But I didn't not no.

03:37.190 --> 03:44.180
And as I wrote here you might be thinking isn't this redundant because if we have a default value it's

03:44.180 --> 03:46.470
already saying it won't be no.

03:47.120 --> 03:57.720
If we go back and we look at cat's regular cat if we do an insert into cats just like this.

03:57.720 --> 04:08.240
And if you can remember all the way back to cats we have no default provided and you select star from

04:08.240 --> 04:10.730
cats we get.

04:10.730 --> 04:14.130
No no there's no default values.

04:14.240 --> 04:22.910
And then when we have our cat 3 when I insert something like this right here incertain to Cat 3 it's

04:22.910 --> 04:24.530
totally empty.

04:24.530 --> 04:26.010
We have those defaults.

04:26.030 --> 04:35.140
So when I select star ups from Cat 3 we get no name provided.

04:35.140 --> 04:36.410
Ninety nine.

04:36.950 --> 04:39.000
So why would we want to add.

04:39.020 --> 04:39.970
Not no.

04:40.250 --> 04:45.680
And the answer is that we could still manually set something to be no.

04:46.130 --> 05:00.140
So if I did that here let's do insert into Cat 3 and I'll do name and age name and age values and I

05:00.140 --> 05:06.180
will say there's no name or let's say name is what's another state in Montana.

05:06.350 --> 05:07.960
It's not too bad for a cat's name.

05:08.120 --> 05:09.650
Great state by the way.

05:10.100 --> 05:15.170
And we'll leave age as no explicitly no.

05:15.470 --> 05:16.230
Just like that.

05:17.800 --> 05:26.900
That to do so like star from got three and you can see that there is nothing stopping us from setting

05:26.900 --> 05:33.010
age to be no all that we have it's a default value if you don't specify something it will be 99.

05:33.140 --> 05:38.980
But you're allowed to say no I'm allowed to say this is explicitly an empty value.

05:39.400 --> 05:39.880
OK.

05:40.040 --> 05:45.320
So that's where this comes in name for which are not.

05:45.320 --> 05:45.850
No.

05:45.950 --> 05:47.050
And a default.

05:47.540 --> 05:49.780
And I won't make you sit through me typing that whole thing.

05:49.790 --> 05:53.700
So I'll just copy it but to walk through it again.

05:53.930 --> 05:55.520
Same thing here.

05:55.520 --> 05:59.420
Same with the default We just did not know and not know.

05:59.630 --> 06:03.040
So let's go ahead paste this in.

06:03.200 --> 06:07.190
This is Katz for this time.

06:07.190 --> 06:15.830
If I do describe cat 4 we now have no is no on both and we have a default on both.

06:16.400 --> 06:17.750
So we're almost there.

06:17.750 --> 06:19.860
I know spend a little bit of a long video.

06:20.120 --> 06:31.450
Let's do a insert into cat 4 and we will specify name and then age.

06:32.360 --> 06:41.590
And this time if I do values AUPs and I say name is what's in it.

06:41.600 --> 06:43.630
Let's do Cali fine.

06:43.700 --> 06:47.410
Sort of a state name and age is no.

06:47.690 --> 06:52.150
If I do this this time we get an error.

06:52.450 --> 06:56.650
So not just a warning but an error saying it cannot be No.

06:56.850 --> 06:57.760
And that's what not.

06:57.810 --> 07:04.300
No specifies so important to note that you'll use not know pretty often.

07:04.360 --> 07:09.880
It's a way of basically requiring that something has a value but also saying that it's not allowed to

07:09.880 --> 07:15.380
be know itself which I also included as a slide here in Cat 3.

07:15.430 --> 07:17.140
We can manually insert something as.
