1
00:00:00,150 --> 00:00:00,750
All right.

2
00:00:00,750 --> 00:00:06,120
So if all you care about is the solution, just check out the code following this lecture or pause the

3
00:00:06,120 --> 00:00:06,660
video.

4
00:00:06,689 --> 00:00:12,260
You can see the solution here, but I'll go ahead and go to the process of typing this out very quickly.

5
00:00:12,270 --> 00:00:13,440
I'll kind of speed it up.

6
00:00:14,400 --> 00:00:19,620
So what I like to do is start by defining the rough skeleton of what we need in a SQL file.

7
00:00:20,310 --> 00:00:24,060
So we need a create table employees.

8
00:00:25,530 --> 00:00:28,560
And then within that, we'll have ID.

9
00:00:29,280 --> 00:00:30,510
We'll have first name.

10
00:00:30,810 --> 00:00:32,220
We'll have last name.

11
00:00:33,060 --> 00:00:34,020
Middle name.

12
00:00:34,770 --> 00:00:38,850
And then we have age and current status just like that.

13
00:00:39,270 --> 00:00:41,100
And then we can fill in the data types.

14
00:00:41,100 --> 00:00:44,220
So we know ID is an integer and age is an integer.

15
00:00:44,370 --> 00:00:47,010
And then these are var chars for our cars.

16
00:00:47,280 --> 00:00:48,990
Let's say two, five, five.

17
00:00:50,140 --> 00:00:52,470
Some somebody may have a giant name.

18
00:00:54,200 --> 00:00:55,880
And same for current status.

19
00:00:56,510 --> 00:01:03,980
So then the next thing that we could do is focus on on ID, which we know needs to auto increment and

20
00:01:03,980 --> 00:01:07,550
we also want it to be mandatory and a primary key.

21
00:01:07,790 --> 00:01:09,830
So mandatory means not null.

22
00:01:10,190 --> 00:01:13,140
And the primary key, there's actually two options.

23
00:01:13,160 --> 00:01:14,810
The first one is to do this.

24
00:01:16,490 --> 00:01:18,970
And the second one, just duplicate this.

25
00:01:18,980 --> 00:01:20,570
It's also in the slides.

26
00:01:21,460 --> 00:01:23,920
Is to add it on the end here.

27
00:01:25,330 --> 00:01:28,190
We don't want that underscore there.

28
00:01:28,190 --> 00:01:28,840
There we go.

29
00:01:29,410 --> 00:01:31,330
So these will do the same thing.

30
00:01:31,330 --> 00:01:32,560
But of course, we're not done.

31
00:01:32,860 --> 00:01:35,230
So the next thing would be first name.

32
00:01:35,830 --> 00:01:38,760
And first name is just mandatory, as is last name.

33
00:01:38,770 --> 00:01:44,470
So we'll just add not null and not no middle name we can leave alone.

34
00:01:45,010 --> 00:01:47,650
Then we've got age, which is also mandatory.

35
00:01:50,540 --> 00:01:55,400
And then finally current status, which is mandatory, but there's also a default value.

36
00:01:55,400 --> 00:02:04,220
So we want not null default employed and then we need to make sure we have all of the correct commas

37
00:02:04,220 --> 00:02:04,700
here.

38
00:02:08,030 --> 00:02:11,840
Just like that at our semicolon as well.

39
00:02:12,650 --> 00:02:15,290
Copy it and let's see what happens.

40
00:02:15,950 --> 00:02:16,340
All right.

41
00:02:16,340 --> 00:02:17,420
So it looks good.

42
00:02:17,660 --> 00:02:20,390
We can describe employees.

43
00:02:22,280 --> 00:02:27,050
And then if we wanted to, let's just do a single test insert to make sure our default value works in

44
00:02:27,050 --> 00:02:28,340
our auto increment works.

45
00:02:28,340 --> 00:02:38,120
So we'll do insert into employees and we'll do first name, common last name, comment age, and that's

46
00:02:38,120 --> 00:02:38,330
it.

47
00:02:38,330 --> 00:02:43,880
Because everything else either has is allowed to be null or has a default value.

48
00:02:44,930 --> 00:02:51,200
And we'll insert someone with the name of Daura Smith, I guess.

49
00:02:51,410 --> 00:02:54,770
And let's say she is 58.

50
00:02:57,080 --> 00:02:57,640
Copy that.

51
00:02:57,650 --> 00:02:58,490
Paste that in.

52
00:02:58,790 --> 00:03:05,390
Let's do a select star from employees just like that.

53
00:03:05,660 --> 00:03:06,710
And it looks good.

54
00:03:06,710 --> 00:03:09,230
We've got an ID auto incrementing it one.

55
00:03:09,230 --> 00:03:15,860
First name, last name, middle name is null because it's allowed to be age 58 and current status is

56
00:03:15,860 --> 00:03:19,490
employed because we didn't specify one and we have a default value.

57
00:03:19,940 --> 00:03:20,660
All right.

58
00:03:20,660 --> 00:03:27,320
So again, the other solution here is just to put primary key on the same line when you're defining

59
00:03:27,320 --> 00:03:31,460
the column, I prefer to do it that way, but you'll also see it done this way.

60
00:03:31,460 --> 00:03:32,300
Both work.

61
00:03:32,570 --> 00:03:33,080
All right.

62
00:03:33,080 --> 00:03:33,710
That's it.

