Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
0
1
00:00:01,280 --> 00:00:02,304
Hi everyone
1
2
00:00:03,328 --> 00:00:04,096
Till now
2
3
00:00:04,864 --> 00:00:07,168
We have learnt how to create a database
3
4
00:00:07,680 --> 00:00:11,008
Delete a database, create a table inside a database
4
5
00:00:11,264 --> 00:00:14,080
And within tables we know how to insert data
5
6
00:00:14,336 --> 00:00:15,360
Update data
6
7
00:00:15,616 --> 00:00:16,640
Delete data
7
8
00:00:17,152 --> 00:00:18,944
And change the structure of the table
8
9
00:00:20,224 --> 00:00:21,760
Now it is time
9
10
00:00:22,016 --> 00:00:23,040
That we
10
11
00:00:23,552 --> 00:00:26,112
Learn the quering part of the SQL
11
12
00:00:27,136 --> 00:00:28,672
So to start with that
12
13
00:00:28,928 --> 00:00:29,952
We'll need a
13
14
00:00:30,208 --> 00:00:31,232
Good database
14
15
00:00:33,792 --> 00:00:36,096
If you look at the resources part of this lecture
15
16
00:00:36,352 --> 00:00:38,400
There is a tar file attached
16
17
00:00:39,168 --> 00:00:45,312
I suggest you download it and you restore the database from the tar file, I will show you how
17
18
00:00:45,568 --> 00:00:46,080
How to do that
18
19
00:00:47,104 --> 00:00:48,640
Once you have downloaded the file
19
20
00:00:49,152 --> 00:00:50,944
You go to the database path
20
21
00:00:51,968 --> 00:00:53,504
Right click on it
21
22
00:00:54,272 --> 00:00:56,320
And create a new database
22
23
00:00:58,112 --> 00:01:04,256
Let us name the databases supermart DB
23
24
00:01:04,512 --> 00:01:09,120
Underscore DB and save it
24
25
00:01:11,424 --> 00:01:13,472
This will be creating a blank database
25
26
00:01:13,728 --> 00:01:16,288
And within this database we will restore the
26
27
00:01:16,544 --> 00:01:20,384
Tables that we have in the TAR file that I have shared with you
27
28
00:01:21,920 --> 00:01:23,968
If I right click on this database
28
29
00:01:24,480 --> 00:01:25,504
And select
29
30
00:01:26,016 --> 00:01:27,040
Restore
30
31
00:01:30,368 --> 00:01:32,160
The format is tar
31
32
00:01:32,416 --> 00:01:36,768
And filename, you have to select the file that you have downloaded
32
33
00:01:39,328 --> 00:01:42,656
I'll go to the path where I have kept my file
33
34
00:01:54,176 --> 00:01:55,968
So, Remember that
34
35
00:01:56,224 --> 00:01:59,552
Since, it is showing only backup format files
35
36
00:02:00,064 --> 00:02:05,696
You will not be able to see the file that I have shared, you have to change this format to all files
36
37
00:02:05,952 --> 00:02:09,024
And then you can see the tar file, select the file
37
38
00:02:09,792 --> 00:02:12,096
And a click on restore
38
39
00:02:13,120 --> 00:02:14,400
Click on restore
39
40
00:02:17,472 --> 00:02:20,288
It will take few seconds to restore the whole database
40
41
00:02:25,408 --> 00:02:31,552
Successfully completed, so if you open the database, you refresh
41
42
00:02:31,808 --> 00:02:33,088
The database first
42
43
00:02:33,344 --> 00:02:35,904
And you go to the schemas public
43
44
00:02:36,416 --> 00:02:38,464
And if you look at the tables
44
45
00:02:38,976 --> 00:02:41,536
This database has three tables
45
46
00:02:42,304 --> 00:02:45,632
One is the customer table which contains customer data
46
47
00:02:46,144 --> 00:02:48,704
To look at what is contained in this table
47
48
00:02:49,216 --> 00:02:50,496
Will open the query tool
48
49
00:02:53,312 --> 00:02:59,456
And then write select star you know this so just right select star
49
50
00:02:59,712 --> 00:03:00,992
From table name
50
51
00:03:01,248 --> 00:03:03,040
Which is customer
51
52
00:03:03,552 --> 00:03:05,600
And run this query
52
53
00:03:07,392 --> 00:03:10,976
This is the data in customer table
53
54
00:03:11,232 --> 00:03:13,792
It contains customer ID, customer name
54
55
00:03:14,048 --> 00:03:15,840
Segment, age
55
56
00:03:16,096 --> 00:03:20,960
The country to which the customer belongs, city and state of customer residence
56
57
00:03:22,752 --> 00:03:28,128
After this there are postal codes and the region to which customer belongs, also you can see the
57
58
00:03:28,640 --> 00:03:34,784
Type of data that each column is containing so age is an integer, whereas country
58
59
00:03:35,040 --> 00:03:39,904
Is a variable character length and the postal code is a bigint
59
60
00:03:42,208 --> 00:03:43,232
If you do this
60
61
00:03:43,488 --> 00:03:44,768
For the product table
61
62
00:03:45,024 --> 00:03:51,168
We'll write select star from product
62
63
00:03:56,800 --> 00:04:02,944
We'll get a list of products, these have product ids, the category to which the product belongs, the
63
64
00:04:03,200 --> 00:04:06,016
Subcategory to which product belongs and the name of the product
64
65
00:04:07,296 --> 00:04:13,184
And the third table is called sales. So select star from sales
65
66
00:04:19,839 --> 00:04:24,191
So let us run this Select star from sales
66
67
00:04:24,959 --> 00:04:27,775
So these are the sales orders
67
68
00:04:28,031 --> 00:04:29,311
So Order line
68
69
00:04:29,823 --> 00:04:31,103
Is the first column
69
70
00:04:31,615 --> 00:04:35,967
And then come the order ID, order date, shipping date
70
71
00:04:36,223 --> 00:04:41,599
Shipping mode, customer ID so this is the ID of the customer who ordered this particular
71
72
00:04:41,855 --> 00:04:43,647
Sales item
72
73
00:04:43,903 --> 00:04:45,695
And this is a product ID of the
73
74
00:04:45,951 --> 00:04:47,487
Product which was ordered
74
75
00:04:47,743 --> 00:04:51,583
Then comes the sales amount that is the quantity
75
76
00:04:52,095 --> 00:04:53,631
Then is the discount offered
76
77
00:04:53,887 --> 00:04:57,215
And finally the profit that we received
77
78
00:04:57,727 --> 00:04:58,751
So, If you see
78
79
00:04:59,007 --> 00:05:00,543
This three tables
79
80
00:05:00,799 --> 00:05:06,175
Constitutes a database of a supermart. So this Supermarket Store has some customers
80
81
00:05:07,199 --> 00:05:10,783
It is storing the date of the customers with itself
81
82
00:05:11,039 --> 00:05:16,415
This has some products it is storing the data of products in a product table
82
83
00:05:16,927 --> 00:05:23,071
Everyday whichever sales are made, it is storing which customer bought that product and what
83
84
00:05:23,327 --> 00:05:27,167
What was the product ID. So this sales table has
84
85
00:05:27,935 --> 00:05:29,727
Order line as the primary key
85
86
00:05:29,983 --> 00:05:32,799
Each order has a unique order line
86
87
00:05:33,055 --> 00:05:34,591
And within that order line
87
88
00:05:35,103 --> 00:05:36,639
There is an order ID
88
89
00:05:38,175 --> 00:05:42,271
With that order ID, there is a customer ID and a product ID associated
89
90
00:05:42,527 --> 00:05:45,855
Using this customer ID you can see the details of the customer
90
91
00:05:46,111 --> 00:05:47,903
In the customer table
91
92
00:05:48,159 --> 00:05:51,999
And using this product ID you can see the details of the product in the product table
92
93
00:05:52,511 --> 00:05:54,815
And if you look at the first two
93
94
00:05:55,071 --> 00:05:55,839
Order line
94
95
00:05:56,351 --> 00:06:00,191
The order ID is same, what this means is
95
96
00:06:00,703 --> 00:06:01,983
In the first order
96
97
00:06:02,239 --> 00:06:04,287
There were two product ordered
97
98
00:06:04,799 --> 00:06:09,407
So the product ID is different that's why there are two different lines
98
99
00:06:11,199 --> 00:06:14,527
So, Order ID can be duplicate that is why it is not a primary key
99
100
00:06:14,783 --> 00:06:16,575
But order line is unique
100
101
00:06:16,831 --> 00:06:19,903
And that is why it is the primary key
101
102
00:06:21,183 --> 00:06:22,463
For customer table
102
103
00:06:22,719 --> 00:06:28,095
The customer ID is the primary key and for the product table product ID is the primary key
103
104
00:06:30,911 --> 00:06:32,447
So our database is ready with you
104
105
00:06:33,983 --> 00:06:34,495
You
105
106
00:06:34,751 --> 00:06:37,311
Restored this Database from a file
106
107
00:06:37,823 --> 00:06:39,359
How to create that file
107
108
00:06:39,871 --> 00:06:44,223
You need to create a backup of your database to create such file
108
109
00:06:44,735 --> 00:06:46,015
To create a backup
109
110
00:06:46,271 --> 00:06:47,807
You will need to go to the database
110
111
00:06:50,367 --> 00:06:51,647
Right click on it
111
112
00:06:52,415 --> 00:06:54,207
And click on backup
112
113
00:06:55,743 --> 00:06:57,279
Give a filename here
113
114
00:06:57,791 --> 00:07:00,863
And select the format, I selected Tar format
114
115
00:07:01,375 --> 00:07:02,655
And click on backup
115
116
00:07:02,911 --> 00:07:06,751
This give me that file which I have shared with you in the resources
116
117
00:07:08,031 --> 00:07:12,895
From now on all the queries we will be writing will be on this database
117
118
00:07:13,151 --> 00:07:16,223
It is very important that you have these three tables with you
118
119
00:07:16,991 --> 00:07:22,367
So that whenever we write you can write with us and check that you get the same result
119
120
00:07:23,903 --> 00:07:25,695
So in this lecture you learnt
120
121
00:07:26,207 --> 00:07:32,095
How to create a backup and restore a database from the backup file
121
122
00:07:32,863 --> 00:07:35,679
With the restore database, we will be now
122
123
00:07:35,935 --> 00:07:37,471
Practicing the query commands
10079
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.