Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
0
1
00:00:00,300 --> 00:00:03,660
So in this video, we will discuss the last option.
1
2
00:00:04,580 --> 00:00:12,680
To create the Supermart database that is creating individual tables and using the CSV files to load the
2
3
00:00:12,680 --> 00:00:14,300
data into those tables.
3
4
00:00:15,910 --> 00:00:21,650
Now we have three tables in the supermart database, customer table, sales table and product table.
4
5
00:00:22,510 --> 00:00:28,990
We will be creating those tables individually and copying data from the 3 csv files I've given you in
5
6
00:00:28,990 --> 00:00:29,710
the resources.
6
7
00:00:30,850 --> 00:00:33,080
Now, you already know how to create a table.
7
8
00:00:33,550 --> 00:00:41,080
We use the create table command and after that we give the name of the label and list down all the columns
8
9
00:00:41,230 --> 00:00:42,730
along with their data types.
9
10
00:00:44,230 --> 00:00:52,240
So in the customer table, we have the following columns customer ID, customer name, segment, age, country,
10
11
00:00:52,240 --> 00:00:55,180
city, state, postal code and region.
11
12
00:00:57,330 --> 00:01:02,160
And corresponding to each column name, you can check out the corresponding data type.
12
13
00:01:03,760 --> 00:01:10,760
So this is the query which will create the customer table, and then once you have created the customer
13
14
00:01:10,760 --> 00:01:15,430
table, we have to import data from the CSV file using the copy command.
14
15
00:01:16,510 --> 00:01:17,800
So this is the customer table.
15
16
00:01:18,460 --> 00:01:21,110
Let me show you the syntax for the other tables also.
16
17
00:01:21,310 --> 00:01:27,070
And after that, I'll also run these commands in PostgreSQL to show how the tables are being created.
17
18
00:01:31,590 --> 00:01:38,940
So the next table is product table, product table has only four columns, product ID, category, subcategory
18
19
00:01:38,940 --> 00:01:39,780
and product name.
19
20
00:01:41,280 --> 00:01:44,460
And the data for it is saved in the product.csv file.
20
21
00:01:47,180 --> 00:01:53,680
Then there is sales table, sales table has a lot of columns order line, order id, order date, ship date,
21
22
00:01:53,700 --> 00:01:59,060
ship mode customer ID, product ID, sales, quantity, discount and profit.
22
23
00:01:59,630 --> 00:02:02,870
And the data for this is stored in sales.csv.
23
24
00:02:04,020 --> 00:02:08,850
So basically, we are doing two things for each table, we are creating the table and then using the
24
25
00:02:08,850 --> 00:02:12,960
copy command on let's go and run these commands in postgreSQL.
25
26
00:02:20,530 --> 00:02:26,770
So I'm creating a new database called Using csv to showcase how we are creating the database, using
26
27
00:02:26,770 --> 00:02:27,700
the CSV files.
27
28
00:02:40,320 --> 00:02:44,790
So I have copy-pasted the commands from the presentation to my query tool.
28
29
00:02:45,390 --> 00:02:52,170
Now I'll be running these queries to create the tables and then using these copy command queries to
29
30
00:02:52,170 --> 00:02:53,130
import the data from
30
31
00:02:53,340 --> 00:03:00,960
csv file, note that the csv files are put in the installation directory of postgreSQL.
31
32
00:03:01,080 --> 00:03:05,410
So this was my installation directly within the installation directory.
32
33
00:03:05,910 --> 00:03:12,780
We had the data folder and there I have created a new folder called Data Set and I put the three files
33
34
00:03:13,080 --> 00:03:14,040
in that folder.
34
35
00:03:15,360 --> 00:03:22,950
I have done this because usually PostgreSQL has access to only the installation directory and for all
35
36
00:03:22,950 --> 00:03:30,420
the other locations on your PC, it may not have access, so it is safer to put the files in the installation
36
37
00:03:30,420 --> 00:03:33,000
directory so that PostgreSQL can access them.
37
38
00:03:33,900 --> 00:03:36,170
Now, let's run these commands one by one.
38
39
00:03:39,980 --> 00:03:46,550
So I have run the create table command for customer to check out the table is created, I'll refresh it.
39
40
00:03:50,710 --> 00:03:57,860
And I can see that the customer table is now created, but it does not have data right now, if you
40
41
00:03:57,860 --> 00:03:59,620
run the select star for customer.
41
42
00:04:02,740 --> 00:04:11,380
You will see that table is created, but it has no data inside it, also note that I have added this constraint
42
43
00:04:11,380 --> 00:04:18,010
of primary key for customer ID, if you do not specify a primary key, the table, which is by default
43
44
00:04:18,010 --> 00:04:19,870
created is un editable.
44
45
00:04:20,500 --> 00:04:28,360
So to control the table, we have to specify the primary key for that table and for our customer table.
45
46
00:04:28,360 --> 00:04:30,200
The primary key is the customer ID.
46
47
00:04:31,000 --> 00:04:32,970
Similarly, I am creating the product table.
47
48
00:04:34,120 --> 00:04:42,160
It has product ID as primary key, run it, refresh the tables and you will see a product table here.
48
49
00:04:42,880 --> 00:04:51,100
Run the sales creation command, refresh the tables and you will find a sales table also.
49
50
00:04:51,850 --> 00:04:55,510
Now I am selecting the copy command and running it.
50
51
00:04:56,140 --> 00:04:59,460
You can see that the first copy command was successful.
51
52
00:04:59,920 --> 00:05:02,580
So this copy command was for the customer table.
52
53
00:05:03,010 --> 00:05:06,160
And now if I run the select start from customer.
53
54
00:05:08,060 --> 00:05:14,510
You can see that the customer still has the data, similarly, we can run copy command for other tables
54
55
00:05:14,930 --> 00:05:17,210
to import data in all the other tables.
55
56
00:05:18,590 --> 00:05:25,100
So if nothing else works during restoration of database, the last option that we have is to create
56
57
00:05:25,100 --> 00:05:34,610
each table individually and import data into each table using CSV files or text files. So these files
57
58
00:05:34,610 --> 00:05:38,060
are also given in the resources if nothing else is working.
58
59
00:05:38,210 --> 00:05:38,960
Try this out.
6541
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.