WEBVTT

00:02.190 --> 00:10.920
So the code begins with the two SQL keywords create and table that together the name of teachers, the

00:10.920 --> 00:18.690
signal PostgreSQL that the next bit of code describes the table to add to the database following an

00:18.690 --> 00:20.070
opening parentheses.

00:20.070 --> 00:28.110
The statement includes a comma separated list of column names along with their data types for style

00:28.110 --> 00:28.620
purposes.

00:28.620 --> 00:37.710
Each new line of code is on its own line and in indented four spaces so isn't required but makes the

00:37.710 --> 00:39.390
code more readable.

00:39.390 --> 00:40.590
So each column.

00:40.590 --> 00:42.930
So you can also write this like that.

00:43.260 --> 00:46.260
And here like that.

00:47.480 --> 00:53.200
So it but it making writing the codes like that in SQL makes it more readable.

00:53.210 --> 00:59.450
So each column name represents one discrete data element defined by a data type.

00:59.450 --> 01:02.030
So the ID column here.

01:02.210 --> 01:03.590
ID column here.

01:04.250 --> 01:09.020
Uh, two is of the data type of big cereal, right?

01:09.020 --> 01:18.230
So here a spatial integer type that auto increments every time you add a new row title.

01:18.230 --> 01:24.920
So in first of its the big big ID is going to one in second row is going to be three or in second,

01:24.920 --> 01:30.920
one is going to be two, three, four, five, six and so on.

01:30.920 --> 01:31.760
So.

01:32.730 --> 01:34.630
Uh, we also have the force.

01:35.650 --> 01:41.650
As I said, the first row receives the value of one in the ID column and the second row two and so on.

01:41.650 --> 01:49.030
So the big serial data type and other serial types are PostgreSQL specific implementations, but most

01:49.030 --> 01:52.090
database systems have similar feature.

01:52.090 --> 01:57.910
So next we create columns for teachers first name and last name, and for the school where they are.

01:57.910 --> 02:06.070
Teach each year of the data type var car a text column with a maximum length specified by the number

02:06.070 --> 02:10.630
in parentheses, in this case 25, 50 and 50.

02:11.350 --> 02:12.260
Uh, so.

02:13.610 --> 02:19.100
Now, although this is a safe assumption, you will discover over time that exceptions will always surprise

02:19.100 --> 02:19.500
you.

02:19.520 --> 02:22.730
So the teacher's hire date here.

02:22.730 --> 02:29.960
As you can see, our date here, teacher's hire date is set to the data type date.

02:30.430 --> 02:35.080
And the salary column said to the data type of numeric.

02:35.290 --> 02:41.860
So I will cover these data types more truly in next lectures, but this table shows some common examples

02:41.860 --> 02:42.910
for the data types.

02:42.910 --> 02:47.880
So the code block wraps up six with a closing parenthesis here.

02:48.490 --> 02:54.610
Here This is the last the eighth line of code with the close parenthesis and a semicolon.

02:54.610 --> 02:57.430
So now that you have a sense of how SQL works.

02:58.390 --> 03:02.500
Let's run this code in Pgadmin.

03:02.500 --> 03:05.200
So here I will also need to delete.

03:05.230 --> 03:06.040
Oops, sorry.

03:07.210 --> 03:07.600
Yeah.

03:08.200 --> 03:08.910
Like this.

03:08.950 --> 03:09.730
That's it.

03:11.270 --> 03:11.780
Here.

03:12.830 --> 03:13.460
Yes.

03:13.490 --> 03:18.920
Now you have your code and you're connected to the database so you can make the table using the some

03:18.920 --> 03:19.390
steps.

03:19.400 --> 03:23.660
Same steps we did when we created this database.

03:23.660 --> 03:29.600
So open the Pgadmin query tool, as I said, and just click on execute here.

03:32.630 --> 03:34.070
Syntax error hiredate.

03:34.100 --> 03:38.150
We have some errors with higher data and as you can see, we don't have comma here.

03:38.180 --> 03:38.960
We will need that.

03:38.960 --> 03:41.090
And here now let's run it again.

03:41.740 --> 03:42.530
And that's it.

03:42.550 --> 03:46.770
Query turned successfully in, uh, and milliseconds.

03:46.800 --> 03:50.140
Write this here and we will refresh the data here.

03:50.140 --> 03:52.750
And as you can see here we have here.

03:53.930 --> 03:55.370
Foreign data wrappers.

03:56.020 --> 03:57.340
Oxalic has.

03:57.350 --> 03:58.460
We have here.

04:01.230 --> 04:03.360
And we will have themes.

04:03.360 --> 04:13.230
And as you can see here, we have five EFTs aggregative collections and domains and under that.

04:13.990 --> 04:16.090
There is something called tables.

04:16.570 --> 04:20.890
And as you can see here, we add our tables here.

04:22.340 --> 04:23.600
Let's actually view this.

04:24.570 --> 04:32.670
So you can also expand the teachers table node by clicking the arrow to the left like this of its name.

04:32.730 --> 04:40.670
And this reveals more details about the table, including the column names here.

04:40.680 --> 04:46.140
Other information appears as well, such as indexes, triggers and constraints.

04:46.140 --> 04:51.510
So but I will cover those in later lectures and clicking on the table name and selecting the SQL menu

04:51.540 --> 04:52.320
here.

04:54.140 --> 04:55.070
Concrete.

04:55.280 --> 04:57.680
As you can see, there is so much options here.

04:57.770 --> 05:04.280
So click on the table and selecting the SQL menu in Pgadmin workspace will display a SQL statements

05:04.280 --> 05:07.550
that will be used to recreate the teachers table.

05:07.910 --> 05:11.000
And here the congratulations so far.

05:11.000 --> 05:14.240
You built the database and added a table to it.

05:14.240 --> 05:18.980
And the next step is to add data to the table so you can write your first query.
