SQL Table Alias Tutorial for Beginners
SQL Table Alias Tutorial for Beginners
Hello everyone. Welcome to part 58 of SQL for beginners series. In this video session, I am going to
explain and practically demonstrate on how to use alias names with tables.
So, how to provide alias names for tables. This thing I am going to explain in this video session. In one of
the previous videos, I explained how to use alias names for, how to use alias names for table columns.
Table columns. In one of the earlier videos, I explained how to use alias names for table columns. But in
this video session, I am going to explain how to use alias names in SQL statements for tables itself.
Okay? For tables itself. This is what I am going to explain in this video session. Okay.
So let me give some examples so that you can understand how you can use alias names for tables. Let's
say there is a statement guys. Select star from. Select star from. Let's say there is a table like emp. Emp1
table is there. And another table is like emp2 table is there. Okay. Select star from emp1, emp2. like this
is there. So, here, this is a table and this is a another table. Generally, we specify only one table, right?
Select star from table name. Select star from table name. What will happen when you run this
statement it this particular statement will retrieve all the records from all the columns of this emp1
table. But, we can provide multiple tables, guys. Here, only one table is there.
But, if you have to select star from multiple tables, I can provide that emp1 Comma, EMP2. Okay?
Multiple tables i can provide here. So, this statement will retrieve the records not only from emp1 but
also from emp2 table. Same time, I am going to give some alias names here. Okay? For table EMP1, I am
going to give the alias name as O. Okay? EMP1 alias name is O. EMP2 alias name is something like T.
Now here, Now here, what I am going to do is, instead of retrieving all the columns from these two
tables, what I am going to select? O dot, okay? O dot ID. O dot first name, comma, T dot last name. Like
this I can provide. You see, these columns are being retrieved from which table?
This ID column and first name column records. are retrieved from which table? EMP1 table. Because its
alias name is O. I am just using [Link], [Link]. So, these two columns, records will be retrieved from
emp1 table. Whereas, [Link], this column will be retrieved from emp2 table. Because T is the alias
name. Whatever the t have used here. Okay. Just focus on these guys. So, these are alias names. So, for
first table, for the first table that is EMP1, the alias name i have given as O. and for the second table,
EMP2, I have given the alias name as T. So here, instead of retrieving all the columns from all the tables,
so if i specify o dot ID, that means this id column from emp1 table.
Here, I mentioned o dot first name. That means this first name column from same emp1 table because
its alias name is O. Now if i say t dot last name, okay, T is the alias name of the emp2 table. So last name
column from the emp2 table. Like this, guys, we have to use the alias name. So, O is alias name for emp1
table. T is alias name for the emp2 table. Now, I can write more like where where o dot id is equal to t
dot ID. Okay. So, select o dot id comma o dot first name comma t dot last name from emp1 which alias
name as O. EMP2 alias name as t where o dot id is equal to t dot ID.
Like this, we can create the statements. This is how we provide the name for the tables. Let me
practically demonstrate this example. Let me practically demonstrate this example so that you can
understand the alias names in a detailed manner. So, let's go to this MySQL workbench where we can
run the SQL queries on MySQL. So, here we have four databases like QFox, CircularCycle and World.
Current selected database is World as you can see here. But I would like to create some tables and
perform operations on the tables in the QAFOX database. So for that, I have to use QAFOX. This will
select the QAFOX database. Run this. The QAFOX database got selected. After that, I have to create a
table. There are some existing tables, but I would like to create new tables.
So create table EMP. EMP details 1. Create table EMP details 1. So this is a table name. EMP details 1 is a
table name. Now here I am going to say id type int and what is the other thing? First name. First name as
var cap 15. So this is first table. Create table EMP details 1. Just run this. It will create a table. The table
word created. Refresh here. It will appear here. EMP Details 1 is a table. Now into this table I am going
to insert some data. Insert into table name values. First value should be of id int type. So 1 name is Arun.
First name is Arun. This first name is Arun I am inserting. Second record is insert into emp details 1
values 2 comma Varun.
Okay, second uh two id is divine value is world Now, third thing is insert into emp details one values four
comma let's say these are three records i would like to insert into the empty details one table. Run this.
So, these three records got inserted, guys. How to find out whether they got really inserted? We can run
a query, right? Select star from. Select star from EMP details 1. Table name. Select star from table name.
When I do so, it will retrieve all the records. 1 Arun, 2 Arun, 4th Arun. Like this. 1 Arun, 2 Arun, 4th Arun.
Now, let's create another table. Now, let's create another table. Create table. EMP details 2. ID. as int.
Okay. And last name. Other column i am creating is last name where care.
Say 15. so there are two tables. First table is emp details one which has one one column as idea and
other column as first name. But second table is emp details two table. Okay. Which is a different table. It
has ideas in time the last name as a worker Okay. Last name is another column. So let's create this table
first. So, under this table, I am going to insert some data. Insert into EMP details 2. Insert into EMP
details 2. ID I am going to give 1 and last name Moturi. My name, like my last name. Fine, here 1 Arun is
there. ID is 1 and first name is Arun. For the same ID, last name is Moturi. Okay, like that. I am just trying
to create such kind of data.
emp details, two. Then we'll have something like, uh, one, four. Okay. Four. Four as, uh, or two. Two as,
uh, one, two as one minute. Okay. Uh, what we'll do is like, uh, insert into emp details to one motor we
give And, uh, for four, I'm not giving for two guys. I don't want to give for two. so here four directly i'm
jumping to four okay the force uh uh last name, like first name is tarun
and uh for the four last name i'm going to give in the other table like uh like uh kumar okay kumar now
insert into, EMP did another record i'm creating and i'm just giving record number as five you see one
two four is there here here five has come new.
So, here 2 is something which is not there in the second table and 5 is something that is not there in the
first table. 1, 4, 5 and here Rathod something I am giving. This is all data we need for understanding this.
Okay. So, I have to create the data in this way. So, here I have to give values guys. Okay. So, it should not
be like this. Values, values, values. Fine. Insert into EMPT tells two values. First one is 1 motor E. Okay.
Here 1 R1 is there, 1 motor E is there here. first name is Arun and last name in the second table is
Motavi. And here two Arun is there, but here two record is not there okay in the second table.
Whereas coming to the third record, we have fourth Arun here. Here four Kumar is there okay four here
first name is the Tarun second last name in the other table is specified as Kumar. Now EMP details two
values. Last record is five, which is not there in the EMP details one. Okay. This is a new record, new ID,
which is not actually there in the first table. And rather like this, I have to create some database. Okay.
Now select star from EMP details 2. Okay. I have to first run this guys. Okay. I have to first insert this
data. Table got created already, but then I have to insert the data. So that data got inserted into the
EMP details 2 table. Select star from EMP details 2.
So all these three records, 1 motor E4 Kumar 5 Rathod is now displayed. Fine.
So EMP details 1, these three records and EMP details 2, these three records. 1, 2, 4, 1, 4, 5. Okay. Fine.
Now, we have the required tables. Two tables we need. In order for me to explain about this alias names
for table, I need two tables. Okay. So, one of the table I created is EMP details 1 with these details.
Where the other table I created is EMP details 2 with these details. Okay. so now i have to use the
aliases. How to do that? Let me explain. Select. First I will say star guys. Okay. Star. From which tables?
Two tables. So first table is emp details one comma emp details two like this i have to provide.
Now EMP details one for emp details one i am providing a alias name as O. For EMP details 2, I am
providing the alias name as T. 1, O stands for 1, T stands for 2, like that I am just trying to give. EMP
details 1, I am just giving O. EMP details 2, I am just giving T. Now, where, sorry, where, all those things I
will come later. But here, asterisk means all records, right? Asterisk means all records. All records from
all the columns. Hashtag means all columns from both the tables. Instead, I would like to display, okay?
Instead, I would like to specify the column names here. If I specify ID here, if I specify ID here, ambiguity
problem will come, guys.
Okay? Because in EMP details 1, ID is there. In EMP details 2 also, ID is there. Here, two tables are
mentioned. EMP details 1 and EMP details 2. In both these tables, ID column is there. But, If you run this
query, you'll get an error saying column ID in this field is ambiguous. Ambiguous means it's not able to
understand whether I need to retrieve the ID column values from EMP details 1 or whether I need to
retrieve the ID column details from EMP details 2 table because ID column is there in both the tables.
So, using this alias name, we can overcome this problem. That is, you have to specify the O dot here.
Select O dot ID. okay select [Link] means this id column from which table employee details one table okay
then o. first name okay o. first name this is also result and last name belongs to second column the
whose alias name is t so i have to say t. last name like this we have to use the aliases okay these are the
alias names
for the EMP details 1 table and EMP details 2 table. Using these alias names, we can call the table
columns. And these alias names will help you in resolving the ambiguity problem where if the same
column is there in different tables, if you specify O means, this belongs to the employee details 1 table
like that. You can classify that. Now, I am going to add one more condition like where [Link] is equal to
[Link]. So, this ID is referring to which table? employee details table, details one table. This ID is referring
to which table? Employee details to two table because we are accessing that with the help of the
employee details to name, okay? Select O dot ID, O dot first name data last name from em details one,
O, m details two, to T, and where o dot id is called t dot ID.
So everywhere, in every line, we have used names always name here here t is alias name here o is name
t is name always name and t is a layer like this, we can use alias names for the tables okay if you run this,
what will happen? Here, the condition is we have to retrieve these records. Okay? These columns. Data
from these columns. The first two columns are from the employee details one table and this column is
from the employee details two table that's fine okay where o dot id should be equal to t dot id here the
first table, we have one two four Okay? one equal to one when one is equal to one You are getting my
point right, [Link].
[Link] means this one. One is equal to one. So here, [Link]. [Link] means this ID. So if one is equal to one, then
you can retrieve this particular record. Then, two worm. Is two record is there here? Is two is matching
with any two here? There is no two in the two table, right? So this will be ignored, okay? It will be
eliminated. Now, 4 will come. 4 ID is there in the first table. So, [Link], 4 is matching. Then, [Link] also
should have 4. If 4 is equal to 4, this record will be retrieved. Then, coming to 5. So, [Link], there is no
more [Link]. So, [Link]. [Link] is 5. So, 5 is equal to any 5 in this particular EMP details 1?
No. so that will also be eliminated. This is also eliminated. This is eliminated. Only one four are
matching, right? One is matching with this one. One in the employee details, one is matching with one in
the employee details two here because o dot id is equal to t dot id is a condition. So four is matching
with this four. When I run this, only that two records and we'll get three columns guys. ID, first name,
last name. So ID and first name is in first table. Last name is in the second second table So if I say where
[Link] is equal to [Link], so it will print, it will display you these two things along with this one and where
these ids are matching here.
So, that's it, guys. See you in the next video session thank you bye
hello everyone welcome to Part 59 of SQL for Beginner series. In this video session, I am going to
explain and practically demonstrate on how to use different joins like inner join, left join, right join, full
join and self join. So in this video session, I'm going to explain how to use joins that is different joins in
SQL statements. Before moving further, let's find out what is the purpose. What is the purpose of using
joins in SQL statements? What is the purpose of using joins in SQL statements? Let's find out this first. As
the name suggests, what is the name guys of this topic? Joins. As the name suggests, joins means joining
something.
So what can we join in the databases? Nothing but tables guys. Using joins, we can join tables. So, joins
are used in SQL for joining the different tables. This is the purpose of joins case. What is the purpose of
using the joins? The purpose of the joins in using the joins in SQL statements is to join different tables.
This is the purpose. Now, are there any predict sites before we join some different tables? The second
question here is, are there any prereq sites for the tables to get joined, to get joined using the joins in
SQL? Yes, guys, there are. There is a prereq site.
What is that prereq site? Both. Okay. For example, there are two tables and you want to join two tables.
So those two, those tables. Okay. which we want to join using the joins in SQL should have a common
column. Then only we can perform the join. Then only we can join the tables. So, joins when used in SQL
statements for joining the tables. What will be the use? We will get the result. So, generally we will
retrieve the records. Right? So, generally, we will retrieve the records from the table. Now, here, by
using joins, we can join two tables in such a way that records, okay, records from two joint tables will be
retrieved okay we'll join two tables and then retrieve the records from those joint tables. Let's say there
is a table here. Okay? There is another table here. Using joints
before using joins, you can retrieve the results okay retrieve this uh retrieved records from this table,
okay? Let's say this is table, this table. And also we can retrieve records from this table. Separately,
individually we can retrieve the records from this table and individually can retrieve the records from
this table. But when you use joints okay? But when you use joints So, these two tables will be joined
together and the records from, and the records from two tables will be retrieved. The records at a time,
the records from, records from two tables, okay, two joint tables, joint tables can be retrieved. Earlier,
before using joints what's the situation? we can retrieve the records from individual tables separately
but by using joints okay we can join two tables in such a way that the records from two tables will be
retrieved okay not from individual tables but joint tables you can retrieve that is the purpose of using
joints in SQL statements guys anyhow i'm going to practically demonstrate how this is going to happen
okay fine and as part of the predict sites i told that these tables let's say this is stable okay
This is EMP1 table. This table is like EMP2 table, let's say. Now, in this table, let's say there are two
columns. One column is ID. Other column is first name. And other table also has two columns. One of
the column is ID. Other column is last name. So the prerequisite for using the joins, for joining two
tables, for retrieving the records from two tables together is these both tables should have a common
column. Can you see any common column between this EMP1 table and EMP2 table? Is there any
common column? Yes. ID is there here and here. In two tables, in two different tables, we have the
same column that is ID. So, if this kind of situation is satisfied, then only we can use joins.
Okay? If we have, if we don't have a common column between these two tables, then we cannot use
joints joints can be used only when a common column is there in between two different tables that we
want to join for retrieving the records from both the tables so hope you understood uh the concepts,
guys. There is one more thing that i need to explain as part of this joins concepts that is that is What are
the different types of joints available? There are five different types of joints. What are they? One is
inner joint. Then we have left joint, right joint, These are the different types of joins we can use in SQL
statements. Full join, then finally self join. So, there are different types of joins available that we can use
in SQL statements.
They are nothing but inner join, left join, right join, full join, self join. Coming to inner join, we can also
call this inner join as equi join or we can also call that as simple join. Equi join or simple join. Coming to
left join, there is another name for the left join. In some DBMS softwares, left join is also called as left
outer join. Okay. Right join is called as, in some DBMS it is called as right outer join. Then full join in
some DBMS software is called as full outer join. Self join is self join itself. So inner join There are other
names for inner join that is equal join or simple join. There is left join. We can some DBMS they call it as
left outer join and right join, right outer join, full join, full outer join and self join.
So these are the five different types of joins available. I am going to practically demonstrate each and
every type of join that I mentioned here in a practical way. Fine. So this is all the concept of the joins
guys. Now let's move to the practical mode where I am going to practically demonstrate how to use
joins in SQL statements. As you already know, the purpose of using the joins is to join two tables when
these two different tables have a common column. And what is the advantage of joining two tables?
While retrieving the records, we can retrieve from two tables. Instead of retrieving the records
individually from individual tables, we can join two tables and at a time retrieve the records from both
the tables.
That's what is all about joins. Now let me practically demonstrate. So in In the previous video, I have
already created these two tables. We are going to reuse these tables. Select star from EMP details. What
is there in this table? First, let's say use QFOX and then select star from EMP details. In this particular
table, we have the records like this. What are the records? ID and first name is there. ID 124. So, we'll
take this. We'll write down these columns. What is the table name? Table name is EMP details 1. First
table name is EMP details 1. Second table name is EMP details 2. Like that we have two tables. EMP
details 1 table, EMP details 2 table are there. And in the first table we have two columns.
So, I am just going to show you. What are the two columns we have in the EMP details 1? ID and first
name. ID, ID column and first name column. And what about the second table? This is second table guys.
Second table name is EMP details 2. Run this. So, you will get the data. ID, last name.
The columns that are there in the EMP details 2 table are ID and last name. ID and last name. and in this
first table, what are the records available, existing records available? Three records are there. What are
they? Here we have one, then two, and here we have four. Okay? And in the one we have Arun, and the
two we have Varun, four we have Tarun.
And coming to the other table, it has id and last name here also we have let's say three records. And
here we have one then we have what is there let's find out one four and five okay one four five one we
have motori and four we have kumar and five we have rathod like this like this some data is there. That's
fine. Now, these are two different tables. Do these particular two tables have a common column? Yes, ID
is common. Here also one ID is there, here also one ID is there. This is a common. Hence, since these
two different tables have a common column, we can use joins or not. Yes, we can use joins. The two
different tables have the same common column, then we can use joins.
We can apply joins in the SQL statements for these two tables with an intention of joining these two
tables and retrieving the records at a time. Fine. Now, now let's start using the different joints. How to
use them? So, select star from.
Okay? Select star from which tables? Select star from which table? EMP details one. EMP details One,
what you want to do on this table? I want to join. Which type of join? I want to inner join okay select
select star from emp details one table. Inner join, okay? Here, make sure that you are providing the
proper names. Select star from emp details one table. That is the first table. Inner join. What is the
second table that we want to join this emp details one with this emp details two?
Okay? Select star from emp details one. inner join emp details 2. Where? Where? This EMP details 1 dot
id. Okay. EMP details 1 dot id is equal to emp details 2 dot id. EMP details 2 dot id. Like this we have to
write a statement. If you have to use inner join. Okay. It's not on where guys. It's on. Okay. So make sure
that you don't write where here. Okay. Have it. by habit we write where here but better to remember in
case of joins we have to write on instead of where we have to write on select star from emp details one
that is the first table and join this first table with the second table for that which type of join we are
using i told five joints are there right five different type of joints what are there we have inner join then
we have left join right join uh full join
and finally self join these are the different type of joins there. Okay? I'm going to use each and every join
here. Now, I started by using the each type of join, inner, first type of join, that is inner join, which is also
called as ekp join or simple join. Fine. So, how the inner join is going to join these two tables? Every join
has a way of joining two tables okay so here if you use inner join, it will join these two tables in a some
way. If you use left join, it will join these two tables in some other way. Right join, it will join these two
tables in some other way like that full join. It will join in another way and so on.
Okay, so select star from emp details one inner join emp details two on emp details dot uh dot id okay is
equal to mp details two dot id and put a semicolon here so here i am saying in emp details one dot id
and uh here i am saying mp details two dot ID. So here id is the common column, right? as i already told
you, if you want to join these two tables, these two tables should have a common column. Here is
where we are using that common column. Okay. ID is there in both the tables. So first type of id is
employee emp details one dot ID. This is emp details two, second table dot ID. Okay. So we have to
write something like this on emp details dot id is equal to mp details two dot ID.
Then only Okay. Then only this statement will be completed. So when you use any type of join, you have
to add this statement at the end. Okay. So this is, this is like a common column. Okay. This is just to
confirm that there is a common column between the, in between the two tables. What is the common
column? ID, ID. So we have to write that here. Now select star from emp details one, inner join with
other table that is emp details two on this dot ID, this column dot first table type dot id is equal to
second table dot ID. So in this kind of situation, how the inner join is going to work, how inner join is
equal to join these two tables.
So these two tables will be joined and the records will be retrieved from these two tables by common
columns, okay? So ID is a something we are using for the common purpose. For example, if you draw the
circuits like this, okay? understand this guys uh this is the emp details one Okay. So here we have ID.
Here we have ID. This ID details we are writing. So here one one is also common. What is common? four
four here. Here one is there. Here one is there. Here four is there. Here four So intersection there will be
one and four but coming to the this place we only have two here. But this place we have only five like
this this is a this is how we can divide.
Now, inner join means uh inner join means this intersection part. Okay? The common, common records
will be retrieved, guys. So, common records will be retrieved by joining these two tables. Only the
common records 1 and 4 will be retrieved by joining the two tables. That is one arun motori then two uh
two is not there. So, it will be ignored. four is there again common okay intersection inner join so four
four uh four tarun kumar will be coming. Okay, you can see that in the result guys. Only the common
records. Okay, only the records having the common values. Only the records having the common IDs,
let's say. Because ID is the common column here, right? Only those common column values which are
common between two tables.
This particular data, ID first name is from first table. And ID last name is from the second table that is
emt details too but we got the result in a single, okay? From two tables, we got the joint result one arun
one motori fourth arun four Kumar. Like that we got, we will get, okay? So this is how the inner joint
works. The next type of joint you will you will understand each and every joint, okay? When I explain
different joint. you'll understand how the different joints are different from each other. Fine, left join.
Left join means, here, the first table is going to be the left and second table is going to be the right. You
see, this is the left table, this is the right table.
This is the first table, second table. So, first table is going to be the left table, second table is going to be
the right table. When I say left join, when I say left join, first what happens is, it's not about common
mistakes, okay? So if I change inner join to, let's say, only I have to change inner join to left to join here.
That's it. Remaining complete statement is same. Select star from EMP details 1, left to join. Instead of
inner join, we have to provide left to join, EMP details 2 and remaining thing will be same. So when I
provide left to join, the importance of retrieving the records will be given to the first table. That is EMP
details 1.
So all the records from the first table will be retrieved. That is 1, 2 and 4. this complete circle, okay? Left
circle. Left join means left circle, right? This left table. This complete left, if I am using left join, this
complete left circle, that how many records are there in left circle? One, two and four, three records are
there. So, it will be like this. So, one, one Arun, okay? Then two is there. Two Arun. First, these records
will be retrieved. 4, Tarun. Like this, 3 records got retrieved. And also, joining will happen now. And also,
the joining will happen. That is, 1, 4 is already there. So, in place of 1, 4, how they will be joined again? 1,
4 will come here.
And here, one more record is there, 5. So, 5 will come here. here 2 is not there, right? So here, what
happens is this 5 will not come. Only the records in the left table will be considered, not the records in
the right table okay first all if you say left join, the records that are there in the left table, that is 1 to 4
will come. And then after considering these three records, then the right table will be joined to this left
table. While trying to join this right table, this 5 is not there in this list. So, 5 will be ignored guys. Only 1,
4 will be considered. Because 1, 4 are there.
Now, is there anything at the place of 2?
No. So, here null will come. Null value. Okay. And here, in place of Arun, we have for 1 Arun, Motori is
there. So, Motori will come. This is how the tables are going to join guys. When you say left to join, all
the records from the left table will be considered first.
Okay. And if there are any common records in the right table, those will be considered like this but uh
non-common records will be ignored. Fine. So, Varun. Varun, we don't have anything in the last name.
So, null is there. Tarun, we'll get Kumar. So, this should be the result, guys.
Okay. This should be the result. one Arun, one motory two Varun, null, null, four Tarun, four Kumar.
Something like that. We should get the table.
Let's run this and see whether what kind of data we got. So, for 1, 2, 4 we got. Okay. 1, 2, 4 we got. 1, 2,
4. So, Arun, Varun, Tarun is there. For Varun, we got two null values.
Okay. For the right side of the table, we got two null values. Now, the next one is right join. Okay. Inner
join is there. Left join is there. Now, right join. Right join means, now you can understand guys how to
get the results. Okay. You should be in a position to, if you understood left join, you can understand right
join. the importance is given to the left, right table first. Because this is right join means right right table
okay what are the different records in the right table one four five so so here the importance is given to
the right table.
So, this records will be first written. That is one four five and uh we have motory. This will be retrieved
first. Okay. Motory. And here we have Kumar. Then we have Rathod. Right? Then we have Rathod. So,
like this. 1 Motri, 4 Kumar, 5 Rathod. Fine. Now, to this records. Okay? To this records. This is the right
table. Left records will be joined. Okay. Based on this records only, this left records will be joined.
Because this is right join first the right table should be retrieved. Then left will be joined to that. So, since
one four five is there. Here, one is there, four is there. Only one and four are common in this right table.
But two is not common. So, two will be ignored.
Okay. two will not be joined. Only this one and four records will be joined. So, in case of one Arun. In
case of four Tarun okay like this and the same thing, 1 and 4 will be there anyhow. So, 1, 4 will be there
and coming to the other one, these two will be nulls. We should get this kind of data, guys. Okay? So,
here, first, right table records will be retrieved. Based on the right table, left table records will be
matched. Okay? If the records are same, if 1 is equal to 1, Then, fine. Here, one is there, so one is
allowed uh two is not there in this right table. So, two will be ignored. four is there in this right table.
So, fourth record uh this record of the second table will be retrieved. Like that. Okay? So, it's like left join
and right join, guys.
Okay? Left join and right join. This is the thing. So, here, one four five will come. And based on that uh
left table will be joined in case of right join. Hope you are understanding this. So, here, right join. Right
join. Nulls will be there at the other table side. You see. 1 Arun. 4th Arun. Okay. 4th Arun. So 1, 4, 5 are
coming. The right table. Right table is completely coming. The right table is completely coming. And left
table will come based on the right table. Since only 1, 4 are matching here. Only 1, 4 records will come.
And remaining record. Since 5 is not there in the left table. None will come. In case of left join. In case of
left join. Full left table will come. Okay. Left table will come fully. And based on this full table. if some
records are matching, those records, according to the common column, some records are matching,
those records only will come. Remaining record will be, since two is not there in the right table, this will
come null. Like this, guys. This is how the tables are getting joined and the results from two tables are
getting retrieved together like this.
So, in case of innergen only the common records, only one four will come. But in case of left join, the
left join complete record, left table complete records,
by joining with the other common records will be retrieved. In case of right join, right table complete
records by joining the common records from the left table will be retrieved. Okay? Now, coming to full
join. Full join is not supported. Okay? Full join is not supported. Here we have different type of joins. We
are done with inner join, left join, right join. But coming to full join, full join is not supported in MySQL. If
you try to run so, you'll get an error guys okay you'll not even understand why this error is coming. Okay.
Even though you have the correct details, but still it is not working you'll get a error in MySQL. So here
what i am saying, full join is not supported in MySQL.
Okay. Full join is not supported in mysql rdbms software. Then where exactly this full join will be
supported? Full join is supported in other rdbms software. That is, oracle in oracle rdbms this full join is
supported guys fine this full join is supported in oracle rdbms so how uh so how to get this oracle rdbms
in my machine only mysql rdbms is there do you have to install and configure the oracle rdbms software
also in my machine it's not required guys because oracle oracle rdbms is being provided with an online
version You can Google it out and get a URL kind of thing. You don't have to install it. Like MySQL,
RDBMS, you don't have to install and configure it for running the SQL statements on this MySQL.
But coming to RQL, they are providing a web URL online. Online itself, you can practice SQL. For
example, if you open this Chrome browser, search for practice SQL online. on which database? Oracle.
Okay. Oracle. Like this, if you search practice sql on oracle database, then you will get this kind of url
where live [Link] okay you don't have to install oracle or dbms in your machine, guys. So if you
simply search in Google, then you will get this particular link and just go there and you have to sign in,
guys. Okay. So you have to sign in. Click on sign in and you have to provide the credentials. Then only
you can work. better to sign in first. So, I'm just giving my credentials for oracle account.
If you don't have, you can have to create sign up and then you can do that, guys. Okay? There are
options to sign up. Now, click on the start coding now. It will take you to this particular page where it will
take you to a uh editor kind of page where you can run your sql queries like this. Okay? This page will
come. Now, here we need to have the same records okay uh we need to have the same records select
star from emp details one okay for that let's create the tables here create table what's the table name
emp details one is the table name run this table will be uh sorry i have to provide the columns right i
didn't provide id int comma first name first name is where cap so 15.
like this you have to provide create table table name emp details one like this you have to provide. So
the table will be created. Into this we have to insert the records. Insert into emp details one table where
one these are the data case okay the same data we are going to insert. That is the same data. one
around two around fourth around like that okay we have the reference. one around. Insert into the emp
details one Two. What is that then the last value is the insert into emp details one four okay we have to
insert this three records but uh sorry again i am doing mistakes. Values. I have to add the values here i'm
missing that. Every time. So values.
Values. This is a statement syntax. Okay. Then only it will work. So three records got inserted. Now, if
you say select star from emp details one table okay all the record data will be, all the table data will be
displayed one round two round fourth round fine uh like this id first name one round two round fourth
round we need to get. So, ID first name, one round two round fourth round second thing is, we have to
create again emp details two table also. let's go here. Create table tmp details to in the brackets. In the
brackets, we have to provide ID. Common column is ID, right? Int. And here last name. Here last name.
Worker of 15. so run this. Second table will be created.
Then we have to insert the data. Insert into. you are preparing the data guys because in mysql already
these tables are there, but coming to oracle DBMS, we don't have this table so we i'm just creating the
tables first. Okay. Insert into table name. What is the table name? emt details two table name values as
one comma. Last name is motor Okay. So like this. Insert into emt details two values. Values as four.
Then Kumar. Just giving Kumar. Then insert into EMP details to values 5 comma some Rathod. These are
the three records we have, right? So, as you can see in this image, ID last name 1 Motori 4 Kumar 5
Rathod. You should get the same. When I say select star from EMP details to second table, run this, you
will get the ID last name 1 Motori 4 Kumar 5 Rathod.
Now we have the two tables ready. In this Oracle RTBMS software also we have the two tables having
the same type of tables. Now the time has come to use the full join. So here as you can see when I say
full join this kind of error is coming. When I try to run this I am getting an error saying unknown column
something but this is not correct. The column name everything is correct but full join is not supported by
MySQL. This full join is not supported by MySQL. So copy this and paste into your arcl Okay, since these
two tables are also created in the arcl rtbms the same statement i am copying. Here, full join is there. If I
run this, what will be the result i will get?
What result i am going to get with this full join, guys? Full join means all records.
Okay? Complete. So, this is known as full join.
So, if i take this full join, this complete thing is a full join. So, how many records are there? total records.
That is one two four five four records are there. one two four five This four records has to come. Okay?
This four records has to come. one two four and five so the data will be something like this. one two four
five Total records. For one Aruli is there. Last name is again one and motori okay like this and then for
two we have Varun. Here we don't have two Right. In the second table, we do not have 2.
So, null, null. Null, null. Then coming to 4, we have Tarun. Then here 4 again. Again 4 followed by Kumar.
This will be the result. So, 5. Here we will get null, guys. Because 5 is not there. Again null will be there
here. Okay. In the left table, we do not have the 5. So, here 5 will come. And then Rathod will come
here. Like this, guys. Okay. 1, Arun. 1, Motori. 2, Arun. Null, null. So, all the records are coming. 1, 2, 4, 5.
Total 4 possible records in both the tables. If you combine these two tables, what are the possible
records? 1, 2, 4 and 5, right? 4 is repeated anyhow. So, like this we have to get the result. In places of no
values, it should be displaying the null.
So, let's run this in the MySQL. I mean, we cannot run this full join in the MySQL. So, let's run this
statement in the having the full join in the Oracle RDBMS like this. Should get the, you see, 1 Arun, 1
motor is coming. 4th Arun, 4th Kumar is coming. You see, for 5, only second table has a 5. So, in the first
table, null values are coming. Here, null is being represented as hyphen, guys. This is nothing but null. In
the first table, again, 2 Arun is there. That is coming as null in the second table. So, all the possible
records are coming. Right? All the possible records are coming. That is nothing but the full join. Now,
final one is self-join.
Final one is self-join. Self-join is different from these four joints. Here, what is the difference between
these four joints and this self-join? In case of these four types of joints like inner, left, right and fold, we
were using two tables. We were using two different tables. But coming to self-join, we have to use same
table. Same table two times. Got my point? Here two different tables will be joined. But here the same
table will be joined two times. Here EMP details 1 is there, EMP details 2 is there. These two are
different tables. So inner join, left join, right join and full join can be used between these two different
tables. But in case of self join, a single table, only one table has to be used and also two times we have
to use.
The same table we have to use two times. to join them. To join. Okay? You will understand more about
self join let me explain self join in a other way. So, now i'm going to explain about the other one. Other,
last join that is self join so in case of self join unlike other joins, we only need one table. We don't need
multiple tables. Okay? Only one table is required to perform this operation using the self join only one
table is required. You don't need two tables. Fine? So, let's create the table, guys. Okay? Let's create
that table. So, we don't need these tables. So, create table. Okay. Create table. EMP details 3. Okay.
Only one table I am going to use. You can see that.
The name of the table is EMP. Otherwise, I will keep EMP details only. It does not have any 1, 2 or like
that. Okay. Create table EMP details. So, here id is int. Then, we have first name. First name as var char
15. Then we have last name also in the same table var char 15 again. And we have some department ID,
the short form DEP ID I am giving. It is also in, let us say. Like this, we are creating a single table. The
single table is created like this, guys. The table is something like this where it has four columns. first
column, second column, third column, and fourth column. Like this, four columns are there in this
particular table the table name is table name is emp details table.
Only one table, okay? I don't need two tables here. Only one table is required, which is having four
columns. The first one is ID. Second column i am creating is first name. Then the third column i am giving
last name. And the fourth column I am giving department ID, DEP ID. Okay. Like this four columns are
there. Under these four columns, I am going to insert some 3D course, let's say. So, like this kind of data,
I am going to insert guys. 1, 2, let's say 3. Okay. Here first name, let's say Arun. Last name is Moturi.
Then here Varun. I am just giving Kumar. Here Tarun. I am giving Rathod. Now here department ID I am
giving 1. Here ID is also 1.
Department ID is also 1. But here in the second record ID is 2 but department ID is 9. Just focus on these
guys. I am intentionally giving a different department ID which is not matching with ID. But in case of
first record this department ID is matching with this ID. But in the second record department ID is
different from the normal id that is two third record we have again have the same id department id is
same as the id now now we can use self join in the single table itself how to use we have to write
something like this self join i mean sorry uh so we have to create the data first guys right first we have
created the this is just for like a display purpose
i created this table before you the same table i'm going to create in this uh db mysql db okay create
table mp details
These four columns, ID, first name, last name, department ID, run this. Once the table got created like
this, then insert the details. Insert into EMP details, values, 1, Arun, Motori, again 1. 1, Arun, Motori, 1.
Then second record, insert into EMP details, values, 2, Varun, Kumar, I am intentionally giving a different
department ID which is not matching with the, this department ID is not matching with the normal ID,
right? Intentionally I am giving, you will understand why I am giving later part of time. Insert into EMP
details values 4, Tarun, Samrathowd, again, so this is three right? So this is three okay? So it's not four
it's three here also three like inside these three records. Now say, select star from emp details.
All the table details will be displayed for us. Run this. You see, ID, first name, last name, department id
so uh for the first first record and last record, department ids are matching with id but for the middle
record, department id is Nine, but uh normal id is two. It's not matching. So, this concept is around this
uh two id skies Okay? Fine. Now, if i say select star from, select star from emp details. Okay? Comma.
Again, I have to say emp details. Fine? Select star from emp details. Select star from EMP details. So,
select star from EMP details, comma EMP details I am giving. Right? Same table I am repeating twice.
Now, I don't have any keyword like, you see, remaining joins like we have inner join.
Okay? The same keyword is inner join I have to use in the statement. Coming to left join, I have to use
left join in the SQL statement. Right? Right join. I have to use right join. this statement, even full join also
have to use. As you can see, if you remember here, full join we have to use we have to use this full join
as a keyword. But coming to the self join, there is no keyword like self join okay there is some not some
there you cannot use like this, okay? This is not there. This is not there. Self join is not there, okay?
Select star from emp details, comma emp details, where? Where, okay? So what to do here? Self join
means,
here i have to provide the alias names for these two tables, okay? Before I demonstrate how to use the
self join thing let us start from emp details. I have to give the same table, right? Twice you are giving that
means uh how can you give the same table twice? You have to replicate, right? You have to give
different names. If you don't give different name for the same table, you cannot join them right the just
understand the concept, guys. Here, in case of remaining joins, we have two different type of tables. and
uh since there are two different type of tables, two different tables, they have different names. But
coming to the self join self join works on the same table.
How to differentiate these two tables now? How to differentiate this same table from same table? Is it
possible? Yes. By giving the alias names. How to give the alias names from the label as explained in one
of the previous videos, okay? After this table name, you have to specify something like, for example, one
okay? first copy of the emp table, that is one. So short form, I am giving O. Second copy of the same
table i am giving T. Like this, we have to give, okay? We have to give the alias names. Then select star
from emp details, same table, O, T, okay? Then here, we will not have some self join keyword is not
there. Instead, we have to use where guys okay self join is completely different from other joins.
it doesn't have any on keyword or self-join keyword. Instead, we'll be using the normal where class
condition. So, where class, where o dot id is equal to t dot id this we have to give okay so uh there is one
mistake here where o dot id is equal to t dot dp id okay this is what we have to write. select star from
emp details. Since same tables are there here, two same tables are there first for the first same table,
I'm giving the alias name as O. For the second same table, I'm giving the alias name is so here, two
copies of the same table are created with the different names. Okay? Same table, but different names
we are giving so that we can identify this table as separate and this table also has separate even though
these two tables are same tables.
Now, if i say o dot ID. Okay? Now, simple thing, guys. In case of self join what you are doing. Here only
one table is there. You are making a copy of the same table. So this is the first table, right? So control C,
control V. Another table you are creating, okay? In case of selfgen you are creating another table. The
same table, you are creating another copy. For the first copy, you are giving the alias name as O. For the
second table, you are giving the alias name as T. So now, now we have two tables.
Even though these tables are same, now we created a copy of the original table. So it became duplicate
table. So two tables are there. Now we can apply the self join so [Link] means this [Link] equal to
[Link] id okay in the same table we have id and department ID, right?
So we are creating a copy of two tables and [Link] is equal to [Link] id okay so like that we are
going to do guys. Nothing more than that. Okay. O dot ID is equal to T dot department ID. They are
creating a copy of the same table. And from one copy, we are taking the ID. And another copy, we are
taking the department ID. So, in order to compare this ID with department ID, we have to create
another copy and give another name. So, from one copy, we will take one column. Another copy will
take another column, which we need to compare. You are getting my point, right? O dot ID is equal to T
dot department ID. We have to compare.
For that we are creating a copy. That's why from the same table we have specified two times with
different names. So that you can compare two columns from the same table by creating a copy of the
same table. So [Link] is equal to [Link]. Now if you run this, what will happen? So the id and
departmentId will compare. Here one is there, one is there, matching. Two is there, nine is there, not
matching. So this record will not be retrieved. Only this first record will be retrieved. Then third record
we have 3 and 3 matching. So this third record will be retrieved. So that's what is the result guys. So 1
and 3. Only 1 and 3. And also this copy table is also coming.
2 times right. So first table and second table. Same table joined to itself. We are joining the same table
to itself. That's why we call it as self join. So we are joining the same table to itself. Here, based on what
condition? Based on whether this id values are matching with the department id values. Okay? Based on
that, we are joining. So, this kind of result we are going to get. one Arun Motori, one one Arun Motori,
one Okay? three Tarun Rathod, three Tarun Rathod. And remaining two varun kumar nine is ignored
because this department id is not matching with the ID. Okay? This is all about the self join guys okay
self join is a join where it joins the same table.
by creating a copy of itself and it will join the results of the same table which got joined. Okay?
Duplicated and joined. Like this. So, this is all about the different type of joins guys. Like inner joins, left
join, right join, full join and self join. So, that's it guys. See you in the next video session. Thank you. Bye.
Part 60:Sub Query(Explaining Single Row Sub Query by Solving different SQL Problems)
Hello everyone. Welcome to part 60 of sql for beginner series. In this video session, I am going to explain
and practically demonstrate on how to use subquery in sql statements. So, what is a subquery? What is
a subquery? Let me explain. Let's say there is a query inside another query, okay? There is a query inside
another query let's uh represent the query in a form of box here, okay?
And inside this query, there is another query. That is inner query. Okay? Inside this outer query, there is
another query. What exactly is a query? What exactly is a query query is nothing but sql statement guys
okay what is nothing but a sql statement uh one example. Okay? Example. Let me give an example.
Example for sql statement or sql query select star from employees. Select start from employees is a SQL
statement. You can also call it as a query. Let's say this kind of, inside this kind of query, there is another
query. That inner query is nothing but, this inner query is nothing but subquery. Okay. Subquery. And
you can even call the subquery as inner query or nested query.
Anything you can call. Okay. There are different names for this inner query, that is subquery, inner
query, nested query. And how this works? The output of the inner query is going to be the input for the
outer query. So when you run this kind of query, which is having the outer and inner query together,
what will happen is first the inner query will run. First this inner query will run and it will give you some
result. That is some records will be retrieved, something. These results will become the input for the
outer query. Based on these results, the outer query will run. I will explain more about this how this
outer query and inner query will work together in a practical way soon in the same video session.
Now, let's move to some other concepts about this subquery. So, other concept is we have to
understand how many types of subqueries are there. There are two types of sub queries okay there are
two types of sub queries one is single row okay single row sub query is one type okay there are two
types of sub queries that is single row sub query and other one is multi row sub query
okay single row sub query multi row sub query there are two types of sub queries fine now now so what
is the single row sub query And what is a multi-row subquery? For example, this inner query or subquery
is something like this. Select star from employees where EMP underscore ID is equal to one.
How many records will be retrieved from this? Only one employee will be there whose ID will be one,
right? Only one record of an employee will be there in the employees table having the EMP ID as one. So
this will result in only one record. result will be only one record, right? So if your subquery is a, this kind
of sql statement, which is only retrieving one record, okay? That means the input to the outer query will
be only single record. Then you can call that kind of subquery as single row subquery, okay? Subquery
having this type of, okay? This type of sql statement is known as single row subquery. Single row
subquery and Let's say there is another SQL statement like this.
Select star from employees. Select star from employees. So it will retrieve multiple records. Multiple
records will be retrieved when you run this select star from employees SQL statement. So if your
subquery is like this, which will retrieve multiple records and which will be provided as input to the
outer query, then this kind of subqueries are known as multi-row subquery okay this type of sub queries
are known as multi-row subquery so in this video session i am going to explain only about the one type.
That is first type of sub queries that is single row. In the upcoming videos i am going to cover this type
okay the current video session, in this video session i am going to cover single row subquery examples
only.
The next are upcoming video sessions i am going to cover the other type of sub query that is multi row.
So let's go to the practical mode where i am going to practically demonstrate the different examples for
single row sub queries okay singular sub query concept. Fine. So where i am going to practically
demonstrate, let me go to w3 schools. Type this try sql google search for this w3 schools try SQL. You
will get this link guys. First link. Click on that. It will take you to a particular page where you can enter
your queries and these are all, these are the existing tables and you can perform operations on these
tables fine here i am going to write my sql statements. Okay.
So how to, how to write the sub queries and all those things i am going to explain in a practical way now.
So let's take one example. Okay. So one problem or uh one problem statement let's take and let's try to
solve that. The problem here is Find all the customers in the customers table. This is about the
customers table guys. If I say select star from customers. Select star from customers. And in this
customers all the customer records came here. So the question here is find all the customers in the
customers table who are from the same city of, okay? Same city of this person. Let's say there is some
person. Let me find out that person. Okay. So, that person name is here, guys.
harry Kumar, okay? So, harry Kumar. Let's control f and such. A lot of records are there. Yeah, this
person. Okay? I would like to find the other customers from this table who are from the same place,
same city of this harry Harikumar. Harikumar is from which city? He is from London city. Okay. Now, the
question here is find all the customers in the customers table who are from the same city of Harikumar.
This is a question guys. Okay. This is a question that I am going to solve. So, this question if I have to
solve, have to use which concept? I have to use subquarius concept. Then only I can solve it. Okay. Find
all the customers in the customers table who are from the same city of Harikumar.
So, let us say Select. Okay. Select. Uh, city. Okay. I would like first, first thing that i have to find here is i
have to find out from which city this harikumar is there. Okay. From which city the harikumar is from
later. I can find remaining customers who are from that particular city, but first i have to know the city of
this harikumar right select city from which table customers table where this contact name. Okay.
Contact. name is equal to harikumar okay harikumar if i run this, select city from customers table where
contact name is called harikumar what will be the result of this? This will give you the city of this
harikumar city where harikumar is from so run it he is from london guys the answer is London.
Okay. This is the first query i have written. Fine. I got this query. So now, now the thing here is, now i
would like to find the customers who are from the same city. This statement is resulting in one only one
record or multiple records? Only single record, only one record, and that to the city is coming as output,
right? This output of this particular statement, I have to provide the brackets like this, okay? I would like
to make this particular statement a subquery of another query, okay? A internal query of inner query of
another query. So for that i have to surround this, uh, statement with circular brackets and here outside
this subquery I am going to write something like this. Select star from customers okay where city is
equal to if I write something like this.
Select star from customers where city is equal to the city of city of Harikumar. So here this is a query
right This is a query. Inside this query, there is another query. From this circular bracket to this circular
bracket, one query is there. And this query is inside the main query. So, first what will be executed? This
inner query will be executed. What will be the result? This London will be the result. So, when this
particular statement got executed, it will return you London. So, select star from customers where city is
equal to London. All the customers who are from the London city will be retrieved automatically. Run
this. you can see, you'll get the details or records of all the customers, okay, who are from city London,
okay, who are from the same city of Harikumar.
What is the city of Harikumar? Using the subquery we have found the city of the harikumar and this
result of this subquery is being passed as an input to the outer query where we are getting the all the
customers who are from the same city of the Harikumar. This is how we can solve the problems with the
help of subquery this is a subquery and this is the outer query guys this is the outer query inside that this
is a subquery now let's solve more examples. Okay? Let's solve more examples so that you can
understand more. Fine. Next example is finding the second maximum price of products. Here, we have
products table. So, in that uh prices are there. Okay? If I say select price of, okay, select price from
products table table m is products okay
select price from products. If I say all the prices of the different products will be displayed here. And let's
find out the biggest uh price in this. What is the biggest price? Let's manually find it. 18, more than 8 19
is there. 10 is less. So 22 is more than 19. So it's bigger uh it's still less. 25 is more than whatever we
have seen so far. 30 is greater. 40 is more greater. 97 is greater uh here above 97, what we have? above
97, 123 is there. Right? Above 123, we have to find out no above 123, 263 is there. 263. So, above 263,
do we have any other price which is greater than 263? No. This is the greatest price, maximum price.
The second max price is 123.79. This is the first max price. Now, we have to find the second max price.
First max price is 263. 263. Okay? So, And second max price after 263, we have 123 like that. So the
problem here is we have to find this price. Second max price we have to find. If I have to find the
maximum price, first maximum price, the biggest maximum price, then I have to say select max price
from products. This will give you the max price, the biggest or the largest price we have in the list. But if I
have to find the second maximum price, how to find it? How to find guys? That's the problem, right?
That's the problem guys. I can find the max is a function guys.
Okay. Max is one of the functions in SQL I explained in one of the previous videos. If I simply say select
max of price from products, it will give you the maximum price available in the list of prices. But if I want
to find the second maximum price, is there any function for that? No. Then we can go with the subquery
concept. We can make this as a subquery guys. Okay. This internal one, we can make it as a subquery.
And outside this, the output of this one, we can make as an input to the other outer query. That is select
price. Okay. Select price from products table where price is, I will say less than. Okay. This is the first
maximum price and the second maximum price should be less than the maximum price.
If I do so, all the prices which are less than 263 will come here. Run it. Okay. Here we are getting the
result. Apart from the 263, less than 263 whatever it is there, all the records are coming here. Now, out
of all these records, what is the maximum price? I will find out. Out of all these records of the prices
which are less than the maximum price, if I say select maximum price from products where price is less
than the maximum price. This is going to be the second maximum price. Run it, you will get the 123.79.
Like this. Now guys, This is a subquery which is giving the maximum price as an input to the outer query.
And from the outer query, we found the second maximum price.
Now, I want to find the third maximum price. Then what I will do is I will make this complete thing into a
subquery like this. Okay. And this is the input. This is the input. And third maximum price should be less
than 123. Right. So, I will again write select star from 123. select price from products where price is less
than. If I run this, all the prices which are less than that 123 will be displayed here. And in that remaining
prices which are less than this 123, I want to find the maximum price. This maximum price is going to
become the third maximum price. So, 97 is the third maximum price of the product. like this, if you want
to find any number of, any level of maximum price, first maximum price, second maximum price, third
maximum, fourth maximum, you have to make the the entire statement into a subquery and you have
to build another outer query on the top of that to get that kind of results.
Similarly, let's go with the another example display the product sold at the least price. Another question
we have is display the products which are Sold at the least price. Least means less price. Like out of all
the prices, it should be the least price. Display the products which are sold at the least price. This is the
products table. Here, these are the prices. There are lot of products are there. I want to find out the
product which is sold at the very least price. Completely least price. The bottom price. I want to find out.
For that, what I have to do? First, I have to find out the least price, right? First question is, I have to find
the price. Select price from products.
If I say select price from products, what will come? All the prices of these different products will come.
So, any mistake, products, products, okay? Some small mistake is there, run it. So, all the prices of the
products which are available in the products table will be displayed. In that, what is the least price? How
to find? We have to find, use a function known as min function. Okay. Select minimum function, min
function of price. If I say that, the least price will be displayed. 2.5. Now, but my question is, I have to
find out all the products which are sold for the least price in this products table. Okay. So, I have to make
this as subquery. Then, this subquery should be passed as an input like select.
star from products products where price is equal to the lesser price. Okay. Least price. Select star from
products where price equal to least price. Run this. So, this is a product. So, if you only want the product
name instead of hashtag symbol you have to change to product name. Product name. So, it will retrieve
the product name whose price is Okay. The least price. So you can even say price here. Okay. So run it.
So G E I toast. Okay. G toast is the least prized product in this products table. Like this we can find solve
many complex problems with the help of sub queries guys. Okay. Sub queries. Using sub queries we can
solve many complex problems that cannot be solved using the normal simple queries.
Okay. So there is another type of Subquery. So far, all the sub queries are resulting in single record. If I
say select minimum price from products, it will give you only one record, 2.5 watt okay? Only one record
is coming. But there may be some situation where you may get multiple records from the subquery. So
that type of subquery is known as multi-row subquery. In this video session, I am not going to cover
multi-row subquery because i have to explain about different operators, okay? In order to use this multi
row sub query we have to use different operators like in any all exists okay so multi row sub query i have
to explain about in operator. In order to use multi row sub query we have to use in operator, all
operator, any operator, exists operator.
Like this, many operators are there. which we have to use with the multi-row subquery to work. So, I am
going to explain about multi-row subquery with these different operators in the next and upcoming
videos, guys. So, that's it about the subquery and solving different problems using single-row subquery
in this video session. In the upcoming videos, I am going to cover about the multi-row subquery with the
different required operators like in any all-end exist, guys. So, that's it, guys. See you in the next video
session. Thank you. Bye.
Hello everyone, welcome to part 61 of SQL for Beginner series. In this video session, I am going to
explain and practically demonstrate on how to use IN operator. So, in this video session, I am going to
explain how to use IN operator in SQL statements.
What is the purpose of using the IN operator in SQL statements? What is the purpose of using in
operator in SQL statements without in operator without in operator we can only give one value in the
where class where class condition let me give an example for this without in operator we can only give
one value in the where class condition For example, if I say select star from customers where country is
equal to USA. Here which operator I am using? I am using equal operator. So in case of equal operator or
greater than operator or less than operator, whatever it is, we can only give one value, right? To this
particular country, we can give only one value. Only one value is possible.
But with the help of in operator, we can provide multiple values here. Let me show you how that is
possible. Select star from customers where country in operator. Instead of equal operator, we are giving
the in operator. Where country in, in the circular brackets, we can provide multiple values. Here only
USA is there. But here USA, UK. USA, UK, you can give any number of countries here. Italy, France, Spain.
Like that we can keep on giving any number of countries. Like this. So here, because of this in operator
in the where class condition, in this where class condition, we can provide multiple values. We can
specify multiple values. Here, this particular statement will retrieve all the customer records who are
from the different countries like USA, UK, Italy, France, Spain.
But coming to this statement, okay, coming to this statement, it will only retrieve the customers who are
from the country, only USA country. But here, this statement will, the next statement will retrieve the
customers from different countries like USA, UK, Italy, France, and Spain. So this is how, guys, This is the
purpose and advantage of using in operator in the SQL statements. When you want to assign multiple
values in the where class condition, then you have to go with the in operator function.
Let me practically demonstrate how to use in operator. So let me Google W3 schools try SQL. Click on
some link. Clear everything. That came by default. Here we have customers table. I will first select start
from. Customers. Okay? Run it.
It is a normal statement which will retrieve all the records from all the columns of the customers table
here. So here, different country records are displayed like Germany, Mexico, UK, Sweden, France, Spain,
okay? Brazil. Like that, many countries are there here. Lot of countries are there here. Denmark and all
those stuff. Okay? But if i want to retrieve the records of the customers, okay? Retrieve the customers
records who are from the Country, USA. Okay. Only USA I want. Only USA I want. All the customers who
are from country usa want in that case, I have to provide the where class condition where where for
where class followed by the condition. Here I have to specify the condition. In case of condition, I will
say country is equal to usa i will say okay this is a text this is a text guy so you have to provide this
particular text in a single, between the single quotes.
Okay. Run this. So, all the custom 13 records are there of the customers who are from the Only country
is USA. Only USA got displayed. But if I want to filter out the records of the customers who are not only
from USA but also from UK, Italy, France and other countries. France and Spain like that. So all these
different countries I want to retrieve the records from. Here only one value is possible. But if I have to
specify multiple countries, if I have to retrieve the customer records from multiple countries, here only
one value is possible. So, with equal to, equal operator, only one value is possible. If I convert this equal
operator with in operator, okay, country in, here, you have to provide the circle circular bracket,
followed by the list of countries you want to retrieve the data from.
USA, UK, Italy, France, Spain, and so on. You can give as many number of countries as you want. Select
this and run this. Now, total 40 records came of the customers who are not only from usa but also from
UK, Italy, France, Spain. Okay. You see, whatever the countries list i gave here, those will be the records
uk france came france uk spain okay italy italy and uh okay that's it like right spain and italy france usa
uk everything came here so total 40 records are there. Now, let's say i have another requirement where
I want to retrieve the customers. I would like to retrieve the records of the customers who are not from
any of these specified countries. The customer records that I want to retrieve should not be from USA,
UK, Italy, France, Spain.
In that case, what to do? I have to specify not here. Instead of in, I have to say not in. Retrieve all the
customer records who are not in, who are not from. or USA, UK, Italy, France, Spain like that. Run it. So
52 records came and you see all the countries displayed here will not contain any of these country
names like USA, UK, Italy, France, Spain will not be there anywhere here. All the remaining countries
records of the customers got displayed here except the customer records who are from USA, UK, Italy,
France and Spain. Like this guys we can use in operator not in operator for specifying the multiple values
in the where class condition. So, guys, this is how we have to use in operator in SQL statements.
But there is more, guys. But there is more. In operator is mainly used in multi-row sub-quiries. Okay?
Multi-row sub-quiries. In the previous video session, I explained what is a multi-row sub-query. Right?
So, to recap at a high level, there is a query. And inside that, another query will be there. Right? This
kind of queries. This is an inner query. and this is the outer query. If this inner query, inner query is
known as nothing is called as subquery okay if this subquery okay subquery sql statement is, is returning
or resulting in multiple, multiple, multi records, okay? Is resulting in or giving you multiple, multiple
records as an input to the outer query, okay? In this case, the outer query have to use, in operator okay
one of the operator has used to manage this multiple records is in operator single record no need to use
in operator but here the inner query is giving you the result as multiple records there we have to use in
operator not only in operator guys we have any operator all operator exists operator okay apart from in
operator we have other things so all these things i am going to explain in the upcoming videos guys how
to use in operator with the sub queries is a is a thing i am going to explain in the upcoming videos guys
So what I've explained is the basics of the in operator, but how to use the in operator with the multi
rows of queries.
I'm going to explain that in the upcoming videos guys. So that's it guys. See you in the next video
session. Thank you. Bye.
Hello everyone. Welcome to part 62 of SQL for beginner series. In this video session, I'm going to explain
and practically demonstrate on how to use in operator with multi row subquery.
So in this video session, I'm going to explain how to use in operator with multi row subquery. First of all,
what is a multi row subquery? Let me explain that. I already explained in one of the previous videos, but
let me explain again. Let's say there is a query.
There is a SQL query here. SQL query is there here. Inside this SQL query, there is another SQL query.
Inside this SQL query, there is another SQL query then this this main query, outsides query is known as
outer query okay the inner query is known as inner query. The inside query is known as inner query.
Fine. So, this inner query is known as a query which is there inside another query is known as subquery.
It is known as subquery and there are two possibilities for a subquery. For example, this inner query is
resulting in single record, only one record. When you run this inner query, it is giving you only one
record. We can call such kind of inner query or subquery as single row subquery.
If this particular inner query is resulting in only single record, then that subquery is known as single row
subquery. But if this inner query is giving you, when you execute this inner query, it is giving you
multiple records. Then this inner query is known as or the sub queries or inner query is known as multi
row sub query. Right. So in this video session, I'm going to explain how to use in operator with multi row
sub query, which will result in multi records. OK, it will retrieve multi records. When you run this query,
you will get multiple records, more than one record. So in this video session, I'm going to explain how to
use in operator. with such kind of multi-row subquery. Let me practically demonstrate with a realistic
example.
So before going to that practical demonstration of how to use in operator with multi-row subquery, we
have to know one more thing that is multi-row subqueries. If you have to work with multi-row
subqueries, we need to use different operators. In order to use this multi-row subqueries, in the sql
statements, we have to use different operators like either in operator, any operator, all operator, exists
operate These are the different operators we have to use when you, when you have, when you are
working with multi-row sub queries. In this video session i am going to explain how to use in operator,
first operator, that is in operator with multi-row supply now let's move to the practical mode. So here
search for w3 schools, try SQL, okay, try SQL.
And, uh, we'll just open this clear this stuff run this okay fine so there is no query here. That's fine. Now,
what i would like to explain is, I would like to solve a problem. Okay. By solving the problem, we'll
understand how to use in operator with multi-row subquery. Okay. By solving this problem that i am
going to explain, we can understand how to use in operator with multi-row subquery. Fine. So, I would
like to find out the different products. Find the different products which fall into the specified
categories. Find the different products. Let's take this from here to here. What is the problem I am trying
to solve? Find the different products which fall into the specified categories. How to find the different
products?
Forget about the specified categories. How to find the different products? Here we have products table.
If I say select star from products, all the product details will be coming here. But can you see any
category names here in this particular table? Is there any place where you can see category names? Only
product name is there. But category ID is there but category name is not there. But I want to find the
products with help of specified category names only. Instead of IDs, I am just going to provide names. If I
provide some category names, based on that category name, this product should be displayed. The
different products which belong to that particular category should be displayed. Category name should
be displayed. but in this particular products table, there is no category name.
But there is another product known another table known as categories, guys, in which we can get the
category names. You see, select star from categories. Select star from categories. If I say, run this, it will,
it will display all the category names. And it not only has a category name, but also has a category ID.
Okay? From here, we can take the category names and, uh, So, based on the selected category names,
we can get the category IDs. And based on the category IDs, we can find the different products. Okay.
Here, based on the category IDs, we can find the required products. So, here we need two tables. Right.
In this example, I need two tables, guys. That is, for the category names, we have to use categories
table.
Okay. For the category names, we have to use categories table. And for the products, we have to use the
products table. First of all, let's find the, let's use the categories table. So select star from categories. If I
say it will retrieve all the records from the, all the columns of the categories table. Category ID, category
name, description. Here category name is there. Here category name is there. Fine. Now, so what I want
to do here is select category ID. I would like to retrieve the category ID. Okay. Because this category ID, I
can use in the products table, right? First, I will retrieve the category IDs from this categories table.
Select category ID from categories table where category name like some C percentile.
If I give something like this, what will happen is I explained how to use this things, right? Percentile and
underscore. Okay? How to use wild cards in the sql statements is already covered in one of the previous
videos, guys. You can refer you have not followed. Fine? So, what this particular statement is, let's
retrieve all the category ids from this categories table. From this categories table, let's retrieve all the
category ids where the category name starts with c start let's say here some categories are there which
are some category names are starting with b letter. Some category names are starting with c letter.
Some D, G, M, P, S. When I say category name like C percentile, that means these two categories will be
considered here.
For these two categories, what is the category ID? 2 and 3. For this category name which is starting with
C, the category ID is 2. So, 2 will be retrieved. At same time, here C percentile means another. This also
will come because this category name also starting with C. So, 2 and 3 will be retrieved by this. select
category ID, category id from categories where category name like c percent only two records will be
coming. Here multiple records are single record. This query is giving you, resulting you multiple records
or single records. It's more than one. That means multi records. So I would like to make this as a sub
query if i make this if i make this particular statement, SQL statement into a sub query what will
happen?
We can call this sub query as a multi record, multi no sub query Here I explained multi-row sub-query. If
a particular sub-query is resulting in multi-records, then that sub-query is known as multi-row sub-
query. So here only sub-query is there but the main query, outer query is not created yet. So here I will
say select star from products. Select star from products where as I already explained in the products
table, we have the same category ID. Remember, if i launch it in another w3 schools 5 sql and i'll go here
and i'll click on this products, okay? Products, select star from products. If I say like this and run this, you
see, this particular products table even has a category id here cat uh here categories table has this
category at same time products table also has a category ID, okay?
So, that's why i'm saying select star from products where category ID. If I say equal to, this is correct or
wrong? This is wrong guys because when you say category id is equal to, this value should be only one
value. Right? Here the value should be only one value. But this particular sub query is giving you two
records right the sub query is is a multi record sub multi row sub query which is returning you to
records. I cannot use equal to symbol here because if If I have to use equal to symbol, only one value
should be there here. But since this particular multi-row subquery is giving you two records, I have to
use some other operator that is in operator. That's the reason guys, in operator, we have to use in
operator with the multi-row subqueries.
Okay. If you are using multi-row subqueries, then we have to use different operators like in, any, all and
exist. Okay. So I'm using in operator in this video session. Select star from products where category ID in,
select category id from, so this will give you the category IDs. Based on these two category IDs, the
records from the products details will be displayed, okay? Product details will be displayed. Here, based
on the category names, we are getting the products. Run this. So all the products, okay, all the products
which are from the category two and three you see two and three got displayed here. Only two and
three category is one three because this category category name in the categories table we start with c c
and uh remaining okay what are the category names starting with c has the category ideas as two and
three those based on the two and three we are retrieving these values, okay?
This product details. All the products having the category either two or three were displayed here. So
this is how we can solve this, okay? We can solve some problems like this where this is a subquery,
okay? This is a subquery and it's not a normal subquery, it's a multi-row. subquery because it is returning
you multiple records in case of multiple records we have to use in operator that's why we have to use in
operator with multi row sub queries so hope you understood guys how to use in operator with multi
rows of query in a practical way so that's it guys see you in the next video session thank you bye
hello everyone welcome to part 62 of sql for beginner series in this video session i am going to explain
and practically demonstrate on how to use any operator with multi row subquery so how to use any
operator? Okay, there is an operator with the name any, A and Y. Okay, and how to use that with multi
row subquery okay i am going to explain in this video session. Before going further, what is a multi row
subquery As explained in the previous videos,
multi-row sub-query is nothing but a query inside another query. So this is a SQL query. Inside this,
there's another SQL query. We can call this inside SQL query as inner query and outer query as outer
query. This is the terminology. If there's a query, SQL query inside another SQL query. If there's a SQL
query under another SQL query. then this this inside query is known as inner query or we can also call
this inner query as subquery subquery okay and different names are there for this case inner query
subquery or you can call that as nested query whatever it is you can call any of these things generally
used word is subquery we generally use subquery here and there fine and also coming to this inner
query there are two types okay there are two types
inner query is of two types based on the number of records okay based on the number of records that
we can retrieve by executing this inner query we can classify this sub query or inner query into two
types that is if this inner query is resulting in only one record okay then that kind of sub query is known
as then that sub query is known as single row sub query okay single row sub query otherwise If the inner
query, if this inner query inside another query is resulting in multiple records when executed, then that
subquery can be called as multi-row subquery. Like this, we can call this multi-row subquery. So, there
are different operators to work with this. In order to use this multi-record or multi-row subquery, in
order to use this multi-row subquery, we cannot use normal operators.
We cannot use normal operators with multi-row subquery. We can use normal operators like equal to,
greater than, less than with the single row subquery. But for using the multi-row subquery, we need
additional operators. That is, there are three operators like in operator, any operator, all operator. This
kind of three operators are required for using this multi-row subquery. Without these things, we cannot
actually use multi-row subquery. And there is one more operator, guys, that is exists operator. There is
one more operator known as exists operator. But this exists operator is not specific to multi-row
subquery. It can be used with single row also. This exists can be used with single row and multi-row. As
we can even use exists with multi-row, I am just writing it here.
but exists is not specific to multi-row. Exists is, exists, if you have to use exists, we can use with single
row and multi-row. Okay? But coming to in any and all, we can use only with the, we can use them with
a multi-row subquery. They are really needed for the multi-row subquery. But coming to exist it can be
used either with a single row or multi-row also okay so coming to in okay coming to in operator i already
explained this in operator in the previous video. Now, In this video session, I am going to explain about
this, how to use any operator with multi-row subquery.
So let me practically demonstrate this for you guys. Let's go to this page. Okay, just we have to go to the
same URL guys.
Otherwise, in other pages, this particular thing is not working. Make sure that you are in the same page
URL to practice this subquery using the any operator. Fine. I need two tables guys. From this list of
tables, I am going to use order details and products tables, okay? Order details and products.
There is a reason why i am using these two tables, order details and products. So, select start from
orders, if i say. Order details, right? Order details. I'll get some records, all the records from all the
columns of this order details. As you can see, one of the column name is product id here. Okay?
Similarly, if i say select start from products, run this. I got all the records from all the columns of the
products table.
In products table also, we have this product ID. Okay? In products table also, we have the product ID. In
order details also, we have the product ID. So, with the help of this commonness of this product id
between these two tables, we can use this together. Okay? You can use that. We can create the complex
uh multi row sql query statements okay sub query statements fine first thing is that order details okay
we'll start with the order details. slowly we'll move to the any operator guys i'll show you where exactly
we have to use any operator. Select star from order details i will say first. Select star from order details.
Run it. You see product id came and there are here there are some quantities.
Okay. Here there are some quantities. So I would like to use a quantity one. Okay. So let's see uh select
Select star from order details where quantity is equal to 1. Run this.
There is a small mistake here. Run this. This time it got. So, spelling mistake. Select star from order
details where quantity is equal to 1. How many products are there? There are 3 products. Having the
quantity as 1, how many products are there? there are three products. One of the, for all these
quantities having the one, okay? For all these products, quantity is only one, but product ids are
different. One product is having the product id as 37. Another product is having the product id as 19.
Another product is having the product id as 69.
So three are there. Now I would like to only retrieve product ID. Product ID, only one column, details i
want. I don't want all the complete recorder okay? from all the columns, I don't want the records. I only
want the records from only the product id column. So, when i run this,
product, again spelling mistake, product ID. Run this. You see, only the product ID, only the records from
the product id got displayed and uh these are the 37 1969 as you know as you already remember, okay,
all these products have the quantity as one that's why they are coming here, right? These three product
IDs, that is 37, 19, 69. Remember the numbers for a while. Okay. 37, 19, 69. All these three product IDs
have the quantity of those products as one.
Fine. Now I'm going to make this query as a subquery. If I make this query as a subquery, is it a single
row subquery or a multi-row subquery? It's a multi-row subquery because three records are there.
Okay. When you run this subquery statement, how many records are coming? Not one. there are three
records coming. That's why it is called as a multi-row sub query so i'm going to make this as a sub query
anyhow i just surrounded that with circular brackets now. On the top of that, I'm going to say select star
from products where, okay, select star from products where product ID, okay, same. Here in products
table also, we have the product ID. And this sub query is also giving us a product id as a result.
These three product ids it's giving. So, we have to say where product ID, okay, is equal to. Can I say is
equal to? No, you cannot say because there are three, three records coming. How can you say only one
value if you want to assign, you can use equal to. But if you have multiple values, you have to use in
operator. As explained in the previous video, you have to use in operator, right? There is a problem
here, okay? There is a problem here. So, in operator is fine and uh it will uh select start from products
where products in will work that's that's for sure run this okay what's happening products okay products
run this so again spelling mistake. Select start from products where product id in.
Okay. So, here three products are there from the product table having the product ideas 19 37 16 you
remember the product that is right 19, 37, 69.
So this, this subquery, multi-row subquery is giving you three product IDs, right? 19, 37, 69. Based on
this product IDs, okay, product ID in, if I say, all the product, product records, okay, all the records from
the products table having the product IDs as 19 or 37 or 16, 69 will be retrieved. So three products will
be displayed here. That's fine. As ID will be unique, you will get the single records itself. Now, Now, what
if I say less than? Can I use like this? Can I use less than here? Less than. I don't want the 1969, 37 is
there.
Okay. This is not appropriate, right? Less than in is not appropriate. You will get error also. Okay. You
cannot use less than in. So, in such kind of situation where you want to select star from products where
product ID less than. You want to find the product IDs which are less than a particular. these three
numbers. So in that case, you have to use, let's say, any operator. You can use any operator less than
any is fine okay less than any is fine guys but less than in is not fine. Less than any we have to say. So less
than any. Run this. You are getting the results. That means, okay, so the three product ids were 19, 37,
69. As far as I remember, that is 19, 37 and 69.
So here, if I say less than any, there are three records, three IDs, that is less than 19 or either less than
19 or less than 37 or less than 69 should be applied. So overall, what's happening is all the product
details having the product IDs, which are less than 69. So up to 68 only it came, right? Here three IDs are
there. less than 19, satisfied or not? Yes, satisfied because you see, you got the records less than 19. At
same time, any usage any means either less than 19 and also less than 37 also, all the records which are
less than that's also will come along with the lesson along with the less than 19. Okay, the records which
are less than 37 will also come.
So 37, less than 37 records also came because, because of the any any operator and again at the same
time, we have 69 also, okay? So, less than 16 on records will also come. So, 68. So, 68 to 1, all the
records came. Fine? All the records came. This is how it any any was working. Select start from products
where product id less than any. Means, all the records which are coming should be less than 19 and or
less than 37 or operator, guys, okay? Like this, or operator. Either less than 19 or less than 37 or less
than 69. So, all these records are satisfying different less than 19 less than there are few records from
less than 19, there are few records from less than 37, there are few records from less than 69 also.
So, we got 68 records. We got 68 records. Fine? So, this is how guys, any operator will work okay you
can you cannot use any guys okay uh i mean you cannot use less than with in operator. Like this is not
possible. So if you have to use less than operator or greater than operator here, then we have to use any
[Link] okay then we have to use any only. Then only it will work. So, out of all the, okay? So, we got
some multiple product ids here. So, this product details should be less than any of this product IDs,
okay? Any of this product IDs. Either this one, that one or like that, okay? So, like this, this kind of result
you will get, guys. Hope you understood it, guys. So, that's it, guys. See you in the next video session.
Thank you. Bye.
Hello, everyone. Welcome to part 64 of sql for beginner series. In this video session i am going to explain
and practically demonstrate how to use all operator with multi-row subquery. So, in this video session i
am going to explain how to use an operator called as all, all And this operator need to be used with
multi row subquery so in the previous video, I explained how to use an operator known as any with the
same multi row subquery and in this video session I am going to explain how to use an operator known
as ALL with the same multi row subquery
so in order to understand how this all operator works with this multi-row subquery we need to, we
need to find out the difference between these two operators, that is any and all. So, in the previous
video, I explained about any operator and the current video, I am trying to explain the all operator. If
you find the difference, if you, if you know the difference between this any and all, then you can easily
understand all. So, let's say this is the query.
or SQL statement having, this SQL statement having the multi-row sub-query. Whatever I selected here
is a multi-row sub-query, which is a query inside another query, right? And here you can see any
operator is there, right? Here we have to use any operator. So what's happening here in this particular
statement with respect to any operator? Here, this particular statement is returning you three records,
okay? Three product IDs, when you run this product SQL statement or multi-row sub-query, it's giving
you three records. One record having the product ID as 19, another as product ID as 37 and other one as
69. These three product IDs are being returned. Select product ID only from audit details where quantity
is equal to 1. So, these three product IDs are being returned by this multi-row sub-query.
and on the top of that, we have said select star from products where product id is less than any of 19,
37, 69. So what happened is when this in the statement, product id is less than 19 or less than 37 or less
than 69. This is what got executed. Okay. Product ID is either less than 19 or less than 37 or less than 69.
So here our operator. So what happened is few records got retrieved from based on less than 19 few
records got retrieved for less than 19. And along with the above records, less than 37 records, ok There
are few records which got retrieved from the 37, less than 37. And here another one, that is 69, right?
So, few more records which for qualifying this less than 69 product id condition got retrieved.
So, total together okay total together this records, this records, and this records. So, this three type of
records got displayed in the results. Okay, when i run this when i run this here okay here we got the
results of the product IDs, which are less than 69, at same time, which are less than 37, and same time,
which are less than 19 also, okay. All these records got displayed here. But, when i say less than all,
Okay, now the time has come to find out the difference between the any and all. But coming to all, this
works something like this. 19 and 37 and 69. This is the difference guys. Here our operator is there. So all
the records which are matching less than 19, less than 37 and less than 69 got displayed here.
But here less than 99 and less than 37 and less than 69. That means it should be less than 19 only, right?
The answer here is If AND operator is there between this 9, 37 and 69 that means less than 99, 37
means less than 19 only. Here less than 19 or 37 means less than 37 and all other things. But here 99, 37
means less than 19 only. So, 99, 69 is also less than 19. Only the records which are less than 19 will come
here. But here the records which are less than 19, less than 37 and less than 69 are coming. But coming
to this AND operation because this condition will fail in the other records. So, only less than 19 will be
retrieved.
So, only the records up to 18. Here, you see, when I have used all, I mean any, when I used any, I got
records less than 68, right? Less than 68. Here, product ID is being, you can see that, okay? Let me
remove it for a while and then run this so that you will get, you will see the three product IDs. That's
799. 69 are being retrieved by this multi-row subquery, right? Multi-row subquery. When I write this,
write this full statement, So, 30 less than 37 and less than 19 and less than 69 will happen in case of all
operator. In case of any operator, all operator is coming. But in case of all operator, end operator is
coming. So, the records of the products which are going to be retrieved should have the product ID less
than 37 and less than 19 and less than 69.
That means less than 19 only. End operator means only one condition will satisfy. So, this will be only
true when all the conditions are true. So, less than 19 is the only result that we are going to see. So, if I
run this, I will get all the 18 records which are less than 19. Whose product ID is less than 19? Okay. Less
than 19. In case of any, we got less than 69. But in case of all, we got less than 19. Less than 19. This is
how guys, this is the difference between the any and all. Okay. This is the difference between any and
all. In case of any, or operator will come into place. In case of all, okay, end operator will come into
place.
The lesser condition will be applied at the end. So, guys, this is all about how to use all operator with
multi-row subquery. So, that's it, guys. See you in the next video session. Thank you. Bye.
Hello, everyone. Welcome to part 65 of SQL for beginner series. In this video session, I am going to
explain and practically demonstrate on how to use exists operator. So in this video session, I am going to
explain how to use exists operator. In order to use this exists operator, we need to have a subquery in
our sql statements. What is the subquery? As explained in the previous videos, subquery is a query
inside another query. Let's say this is a query. Inside this query, there is another query
okay so let's say here outer query is there. We can call this as outer query and we can call this as inner
query. We have a SQL query inside another SQL query. This inner query is known as subquery. We can
even call it as inner query or nested query. Anything you can call. Generally we call it as subquery. And
there are two types. Two types of this subquery. That is single row subquery single row subquery and
other type is multi row subquery. There are two types. On what basis, on what basis this subqueries
have like single row subquery and multi row subquery have been categorized? Simple guys. If this inner
query, okay, if this inner query is resulting in only one single record, then we can call this subquery or
inner query as a single row subquery.
Otherwise, this inner subquery, is resulting in multiple records, okay? It's resulting in multiple records
when executed. Then we can call this inner query or subquery as a multi-row subquery. And this exists
operator can be used with both types. We can use this with single row subquery or multi-row subquery,
okay? It's a common thing.
Now, I'm going to practically demonstrate how to use exists operator with this subquery in a practical
way. Let me open this and google search for w3 schools try sql and click on this link where we can get
this kind of sql editor. So I present there are no files here. I cleared it out. And you see the tables have
been loaded now. As you can see here, there are different tables, right?
So I want to, I want to retrieve the records from these customers. Okay, before i explain about exists, let
me go through a few statements. So customers table, select start from customers. If I say run it, all the
customer records from all the columns of this customers table will be displayed here. How many records
are there? Total 91 are there. If I say where customer ID is greater than 89. retrieve all the customer
records from this customers table whose customer id should be greater than 89. How many records will
come? Total 91 are there. Total 91 customer ids are there, right? So I am saying greater than, its
customer id should be greater than 89. That means only two records, this 90 and 91 will come when i
run this statement like this right so the customer records got the customer records got filtered here.
Now I am making this as a subquery, this particular statement. SQL statement I am making it a subquery.
On the top of this I am writing another statement. I am going to use another table guys like orders table.
Select star from orders where exists. Here exists operator should be used like this. Select star from
orders. Select the records from orders table where exists of records in this subquery. That means how
this exists operator is going to work? If this sql query, that is sub query is going to result in at least one
record okay when executed when executed if this sub query is resulting in a at least single record, okay?
Then this select star from order statement will work, okay? Run this.
You see, all the records from the orders table got displayed here because this query is executable. and
it's, it's resulting in two records. Since the records are there, this will be treated as true. Okay? Where
exists true. When true is there, this particular statement will be executed. What if i do something like
this? Okay? I do something like this i will say select star from customers where customer id is greater
than 91. Will I get any records i will not get. Right? In the customers table, total 91 records are there and
the last customer id record is 91. Okay? Customer ID is 91. above 91, there is no customer ID. But here i
am saying select star from customers where customer id is greater than 91.
In this case, we will not get any results. Right? If we use this kind of query as a subquery, okay? If you
use this kind of query as a subquery and try to select star from select star from orders table where
exists, what will happen? Here, select star from customers where customer ID greater than 91 subquery
will result in zero records. When zero records will come, this will become false. Since the condition is
false, this particular statement will not be executed. Run this. You see, no results. No results. But what if
I convert into 89? Some records will be there. At least two records are coming, right? Two records will
be coming with this subquery. Since the records are there, records exist, this particular SQL statement
will be executed.
you see, even if i say 90 also, okay? How many records will be retrieved? If I say customer id greater
than 90, total 91 are there. I am saying greater than 90, only one record at least one record we got if at
least one record we will get this particular statement will be executed, you see? The statement got
executed. But if zero records are coming from the subquery, then exists operator will stop this
statement from executing and it will result in zero results, okay? No results. So, how the exist operator is
working? When there are some records resulting from this subquery, then only this statement will work.
If there are no records coming from the subquery, this statement is not going to work because we have
used exist operator.
So, guys, this is how we have to use exist operator with subqueries in the SQL statements. So, that's it,
guys. See you in the next video session. Thank you. Bye.
Part 66:Using Sub Queries for retreiving the records from multiple tables
Hello, everyone. Welcome to part 66 of SQL for... beginner series. In this video session, I am going to
explain and practically demonstrate on how to use sub queries for retrieving the records from multiple
tables. So, in this video session, I am going to explain how to use sub queries okay how to use inquiry for
retrieving the records from multiple tables. Let's say there are two tables. Let's say there are two tables.
One table, let's say there is a table name like city. Another table name is country. Okay? And both these
tables have a column.
A common column. For suppose, both these tables have a common column. So let me draw this. So,
okay, fine. here city, let's say city has one of the column as the country underscore ID, let's say, okay?
Country ID. The same column is there in the country table also. If this is satisfied, okay? If there are two
tables and these two tables have a common column, then we can use, we can use subquery. The
subquery we can use. subquery we can use for retrieving the records from both these tables. We can
retrieve the records in a single SQL statement from both the tables. From both the tables, we can
retrieve the records. If these two tables have a common column, that is here, country ID, country ID is a
common column, and by using the subquery, we can do this, guys.
So in this video session, I'm going to practically demonstrate how to retrieve the records from both the
tables using the subquery when these two tables have a common column.
So let me explain this in a practical mode. So let's get started. So here, in the MySQL workbench, we
have four databases. This database I created as part of one of the previous videos. But these three
databases, that is circular, sys, and whole database, came by default when i installed and configured
mysql in my machine okay so i'm going to use one of the default came databases. I'm going to choose
sakila Okay. Use sakila Run it. After you select the sakila database, then you can perform operations on
any tables of this particular database.
Let's say, as i explained here i am going to use city and country tables okay i am going to use city and
country tables, which are under the secular database. So, let's find out what is there inside the city and
also let's find out what is there inside the country first. How to find out what is there inside the city?
Select star from city we have to say. Select star from city. Run this. When I say so, all the records from all
the columns of the city table got displayed here. City ID. City. You see country ID is there. As I mentioned
here, country ID is there. And last update. Similarly, let's Find out what is there inside the country table.
Select star from country.
Select star from country. Run this. When I say select star from country, all the records from all the
columns of the country table will be displayed here. This particular country table also has the same
column name. That is country ID. Now, I am going to retrieve the records from both these tables. From a
single SQL statement, I am going to retrieve the records from city table and country table with the help
of subquery. That I explained in. I explained about different subqueries in the previous videos. You can
go through that if you are not aware of. Now, I am directly going to use the subquery in this video. Fine.
So, first city column, city table. Select star from city. I will say select star from city and run this.
So, here we have different columns in the city table. I would like to display the city,
okay, city. Here, inside the city table, we have the city column, guys, okay? This is a column and this is a
city. Both the names are same. So, I'm just giving small, just for differentiation purpose, guys, okay? Both
are same. You can give, here if you give city also, it is a table only, okay? But I'm just, just to make you
uh like uh don't have to confuse, right? I just don't want to confuse you. That's the reason i'm giving.
small city here and capital c city here. Okay. Fine. So that you can differentiate between the table name
and the column name because column name and table name are same in this particular table.
Select city from city. When I say so, only the cities, okay, only the cities list from the city table will be
displayed. Fine. Then I'll say, I'll say one more thing. Okay. Other thing is select select city. And here i will
say select star from country okay so let's start from country. Run this. So here, in the country table, we
have the country column. You see, again, the table name and column name are matching that's fine no
no problem i'm just giving country column here. Whatever you are giving the name of the country,
before the from, it will become a column. After the from, it will become a country i mean table select
country from country. Like this, all the countries will be displayed.
But I want the cities and countries together. Okay? You are getting my point, right? Here, select city
from city will retrieve the all the different cities that are there in the city table separately. And select
country from country will retrieve all the countries from the country table separately. But I want both
the cities and country in the same table the same same results the same results here i want to get city
and other here i want to get the country. How to do that? We can use sub queries guys as I told you.
Here I will put a comma. After city I will put a comma and I will copy this complete statement without
semicolon. I will ignore the semicolon here and put a circular brackets here.
How to provide a sub query as explained in the previous videos? I have to provide a circular bracket. In
between the circular brackets I will copy paste this same statement. Complete statement I copy pasted
into this. Okay. So here here what's happening? Select column name is city, comma, another column,
this is this this sql statement is treated as a column here, not a separate sql statement, okay, from city i
am saying, from city. So, one more thing i have to do. That thing is, select city, comma, select country
from city i'll add a where condition, where, where, what is that, here, in this city table also we have a
country ID, and in the country table also, we have a country ID, right?
We have to use that here, okay? City dot, okay? City table dot country underscore id column is equal to
country table dot country underscore id column, okay? As I told you, there are two two tables city and
country. In both the tables, we have the country ID, country id column. That thing i am using in the
where where condition where class condition here this country id if i say only country id and if i don't
specify the table you will get an ambiguous error kind of thing you will get because country id is there in
both city table at same time country table so we have to differentiate how to differentiate we can
provide the table name dot country id this this country id belongs to city table table name dot country id
this country id belongs to country table like that okay so
select city comma select country only when, only when the city dot country id is equal to country dot
country ID. Okay? So that should match.
Then only this, this will be successfully ran this particular statement is possible. If you don't specify the
where class condition, this statement may not be possible. So select city comma select country from
country where and this result is coming as a second column here. Run this, you will see that. Okay? Just
run this first. You will see, first we got city. city column. Second column is this complete subquery is
becoming a second column. You see? But it doesn't look good right uh just to display the subquery as
part of the column name is not good. Looking good.
What we have to do guys in this kind of situation? In this kind of situation where in the results, the
results we are getting the column name as a subquery it's not a good good thing okay what will be the
better way of doing this? Just you need to add alias name like like this okay country or something. So
here, Instead of, when you run this time, this alias name will be displayed in place of this subquery
name.
Okay? So, it will be better. It will be looking better. Run this. See, under city, we got all the cities and
their countries we got. This city is in this country. This city is in this country. So, here you see, Adoni is in
India.
Ahmadnagar is also in India. Like that, many countries, I mean, many cities are there in India. Right?
Alafuza is also in alapi or alafoza okay? This is in Kerala, right? So the city in Kerala, which is in india
itself. And ambattur in India, like that. All the cities which are in different countries got displayed here,
right? This is how this kind of uh this kind of problems if you want to solve in real time, guys, then we
may have to use acquiries in the sql statements so that this kind of things will be possible. Here, how
many tables i used? I used two tables. One is city table, another one is country table, okay? I got, I
retrieved the records from both city table and country table.
Okay. And displayed in a single result. Fine. But there is one more challenge you guys. Okay. Here, here,
this particular thing is only resulting in single record. Okay. So forever for each and every condition
measured here, city, city dot country ID is equal to country dot country ID for each and every match
here. It's this particular statement is only retrieving a single record. Single record for single city. If city is
a Karuna, a Karua or Aba or something, for each and every city, this particular SQL statement is giving
single record. Now, what I am going to do is, I am going to explain a different case where if you reverse
this process, this is not possible. Let me explain that, how this is not possible.
Fine. Here, city, every city belongs to a country. Right? If you give a city name, it will belong to a country.
But if you give a country name, for example, if you give a country, it may have many cities. Right? Right
or wrong every city has see every city has only one country. Okay? One country. But every country will
have multiple cities. Multiple cities. So, this statement is possible because This statement is possible
because every city has a country. That's why you can provide country details in the subquery details. But
if you want to provide city details as a subquery and country details outside, this is not possible, guys.
Because every country has multiple cities and you will get an error.
Let me show you immediately.I will simply say, I will revert the statement, guys. You can see that here
in place of city, I will give country from country table. Like this if I give. and comma i will put here. And
then i will provide a sub query but sub query is going to retrieve the city. Select city from city table
where this is same. Okay. But the problem here is every country has multiple cities. If this particular sub
query is giving you multiple records, because multiple records will come, right? Country will have
multiple cities means this particular thing will retrieve multiple records for each and every country and
uh we do and our results don't know. If a country is specified here, here only one country one here if if
this is a country, then here city has to be specified also with only one city.
But this has a possibility of getting multiple cities for a single country. How can this be possible, guys?
This is not possible. When you run this, you will get an error saying subquery returns more than one
row. For this country, there are multiple cities. You cannot keep this kind of things in a subquery, it will
say. The reverse is possible. Like this, okay? Select city, comma, every city, there is a country, only one
country. So, since there is only one country, you can put the country table details in the sub query okay
but here country has multiple cities. Hence, you cannot put cities thing in the supply this is one thing you
have to understand, guys. You can use sub queries inside the sql statements to retrieve the records from
multiple tables.
But the problem here is, we have to make sure that for every column, there is only one possibility.
Okay? For this city column, there is only one country possible. But here for country column, there is
multiple cities possible, which is not, which will not work. This case will not work. It will give an error.
But in case of this one, it will work. Okay. Every city has a single country. So city name, only one country.
City name, only one country. It's possible. So guys, this is how we have to use sub queries for retrieving
the records for multi tables, multiple tables. Hope you understood this session. Thank you guys. See you
in the next video session. Bye.
Hello everyone. Welcome to part 67 of SQL for beginner series. In this video session, I am going to
explain and practically demonstrate on how to use multiple sub queries in a single SQL statement.
So in this video session, I am going to explain and practically demonstrate how to use multiple sub
queries in a single SQL statement. Yes, guys. We can use multiple sub queries in a single SQL statement.
In order to explain and practically demonstrate how to use this multiple sub queries in a single SQL
statement, let me take a problem. Let me take a problem and try to solve it. As part of that, I will explain
how to use multiple sub queries in a single SQL statement. So what is that problem? The problem is this
one. This is a problem statement.
We need to solve with help of SQL. List out the films. List out the films. having the length less than
maximum length. Okay? Having the length less than the maximum length and having the rental duration
equal to the minimum rental duration of the film. So list out the films in the films table. Having the
length of the films less than the maximum length. Okay? The length of the film should be less than the
maximum length and at same time the film should have the rental duration equal to the minimum rental
duration of the available films. So let me show you the films table first.
So let's move to the practical mode here to solve that problem. And I have this table known as a film
table inside this circular database.
So in order to work with this film table, I need to first switch to this. I need to select this circular
database. Otherwise I cannot directly work. So I have to use a statement like use circular Okay. Use
circular and run this. and i run this this particular database will get selected okay and in this database we
have the film table we have the film table so i have to say select star from film guys this uh circular
database has come by default in the mysql okay the mysql when i installed and configured mysql circular
database came by default so if you have to uh like practice the same example that i am providing here
You need to have the MySQL installed. Then no need to do any other thing.
So I selected the circular database which came by default in MySQL and then I am trying to retrieve the
records from the film table under the circular database. Let's start from film. Run it. So all the records,
all the records, these are all the records guys which are there in the film table. There are several records
you can see. There are different films. Where are the film titles? These are the film titles. These are the
different film titles we have. And what else I was talking about? In this problem statement there are
three things. One is film table which has all the films. List of the films are there in the films table. Having
the length less than the maximum length. I am saying length should be less than the length of the
records that I want to retrieve should have the length less than the maximum length.
Here every film has a length. Okay, here 86 is there, 48 is there. What is the maximum length? How to
find the maximum length guys? Select, if I say select length from film, what will happen? All the lengths
from the film will be come, right? Run it. Okay, LNGTH, spelling mistake. Run this again. Run it. All the
lengths, all the available lengths in the film table will be displayed here. So here I have to find max
length, okay, max of length. maximum length so select max of length from film so out of all this length
which one is maximum here which one is maximum how to find 185 is a maximum okay out of all the
available lengths of the different films 185 is a maximum fine now again select star from film so this
statement is for this statement is for let's put the comments here finding the maximum
maximum length of the available films out of all the films one of the film is having like the films having
the maximum length is this one okay 185 limit the next one next one is so let's start from film all the
records will come again what next after finding the maximum length of the films okay after finding the
maximum length of the films we need to find we need to find the minimum rental duration. You need to
find the minimum rental duration. How to find the minimum rental duration? So, this is a function, guys.
For finding the maximum length, we have the max function in SQL. We have to use that to get the
maximum length. I explained about max function in the previous videos guys okay if you're not
understanding any of these things in this video session, guys, you have to go to the previous videos.
Okay? I explained a lot of things in the previous videos and i'm coming to this video where i'm explaining
the complex problems okay it's not the time to explain the basics. So, all the basics are required for
understanding these topics or are already explained in the previous videos. Hope you understand that.
Fine. Next thing is that, what what i was saying, we have to find the minimum rental duration. For
minimum rental duration also explain one more function in the SQL, that is min function. Okay, min
function. So, let's find the minimum rental duration of the available films. So, there are different films
again. And, uh, every film has a rental duration here. As you can see, there is a rental duration column
here.
Uh, some six, three, same. So, there will be some minimum length, right? Minimum rental duration.
How to find that? Okay. First of all, let's find all the rental durations. Rental underscore duration from,
okay, select rental duration from film. If I say this, it will find the all the rental durations. But I have to
find the minimum rental duration for that i have to use a min function. I have to surround this rental
duration with a min function. And run this again. This time, out of all these values uh rental duration
values, we will get the minimum one. Minimum one is three, guys. Okay? Minimum is three. So
maximum is 185 and minimum is three. Okay? Maximum length is 185. Minimum rental duration is
three.
Now, let's go to the complex query. That is, problem is list out the films. Okay, let's list out the film.
Select star from film table. Okay, run this. All the records will be coming as usual, right? Similar to this
one. So, all the film records will be coming. Here, I want to list down all the film names, let's say. Film
title, I will say. Okay, title. Select title. Comma. What are the other details I want? I would like to take the
length. Okay. length title comma length comma rental duration. Rental duration. All these details i am
going, instead of retrieving all the records from all the columns from the film table, I am trying to
retrieve only these three columns. Okay? This will be enough.
Title of the movie and length of the movie and rental duration of the movie. Okay? From feeling where,
what are the conditions we have in this problem? Having the length less than maximum length where
length of the film is less than maximum length. How to find the maximum length? This is a statement,
right? Select max length from film will give you the maximum length. So, I will use that as a subquery.
You see, this is as a subquery. So, one subquery we already used. Now, I am going to explain in this
video session how to use multiple subqueries in a single SQL statement. And one more condition. and
operator. Okay? and So, where length is less than uh select max length from feeling and another
condition i have to give in the where class by using nine that is the minimum rental duration.
How to find the minimum rental duration? Another sequel statement was there. Select minimum rental
duration from feeling take this and what should be? What should be? The rental duration should be
equal to. Okay? So, I have to say rental underscore duration equal to equal to what minimum rental
duration of the film. So I have to again use a sub query put a semicolon here. And put this sql statement
this sql statement here so here how many sub queries are there sub query one sub query two so in a
single statement i added two sub queries okay will this work? Yes, this will work guys. Run this. So now
you got all the titles of the films. Okay. Having the length less than. maximum length of the film.
So maximum length is 185. 48 is less than 185. 169 is less than 185. 114 is less than 185. And 82,
everything, whatever the lengths that got displayed here for these films have the length less than 185
only. That is less than the maximum length of the available films. And rental duration is equal to
minimum rental duration of the films. That is 3. We already found out, right? 3. So these two
combinations should match. Then only we will get the list of films having the length less than 185 And at
the same time, the rental duration should be equal to minimum rental duration. That is three. Fine. So
this is how guys we can solve complex problems by using multiple sub queries in a single SQL statement
like this.
So guys, hope you understood how to use multiple sub queries in a single SQL statement. So that's it
guys. See you in the next video session. Thank you. Bye.
Part 68:Integrity Constraints
Hello everyone. Welcome to part 68 of SQL for beginner series. In this video session, I am going to
explain about Integrity Constraints. Integrity Constraints.
What are Integrity Constraints? Integrity Constraints are nothing but the conditions that we can apply to
the table columns. The conditions that we can apply to the table columns are known as integrity
constants. There are different types of integrity constants. Types of integrity constants. What are they?
There are different integrity constants like not null, one type. Then we have unique. Second type of
integrity constant is unique. Then we have primary key.
then we have foreign key. Integrate. These are all integrity constant types. Okay. We have different
types of integrity constants which are nothing but not null, unique, primary key. Foreign key. Then we
have check and we have default. Okay. Check is another integrity constant and finally default. These are
the different types of integrity constants that we can use in the SQL statements.
What is the purpose of the integrity constraints? If you want to specify a condition, a particular column
in a table, then you have to use this integrity constants. For example, let's say there is a table. Let's say
there is a table like this. This table has some columns. This table has some columns. One of the column
name is id. Other column name is name.
Let us say another column name is experience. So, let us say this table is employees table. Employees
table. Now, if I put any integrity constant to any particular column. So, what are integrity constants?
Integrity constants are nothing but the conditions that we can apply to the table. Let me explain one
condition. Let us say, let us take this not null condition. not null integrity constant or not null
[Link], how to apply this? Way to apply this we have to we have to apply this condition to a
column only. Okay. Not entire table. Only a particular column let's say i am applying this not null to a
column that is id column. Okay. So, here not null. So, id is applied with not null integrity constant.
Not null integrity constant. so what happens when i apply this, uh, integrity constant that is not null to
this, uh, one of the column of this employees table, that is id column whenever you are trying to insert
some records into this table okay whenever you are trying to insert some records into this table okay
you can skip any data of this columns, but except ID. ID is musterized. You cannot, while inserting the
records, ID is mandatory now, okay? You cannot, uh, make id as null, okay? If you skip the ID, then you
are going to get an error id cannot be null if you are inserting the records and in that particular record if
you are providing id name experience that's all good but if you are missing any id then you are going to
get an error guys you can miss name you can miss experience but you cannot miss id guys because id is
specified with a kind of condition that is or integrity constant that is not null it cannot id cannot be null
going forward like that okay so
Where exactly, how exactly I have to use this not null? Okay. If I have to, if I have to apply this not null
integrity constant to this ID column of this employees table, how to do that? I have to do that while
creating the employees table only. Let's say I'm going to create an employees table like this. Create table
employees. Okay. Same table I'm creating. While creating the table itself, I have to provide this not null
integrity constant to this ID column. Here in the brackets, circular brackets, I have to say id. First column
name is id. Enter. After int, after the name of the column and data type of the column, I need to specify
the integrity constant type. That is a condition I have to specify.
That is not null. Okay. Like this, I can specify. Then comma, what is that? Next column name is name.
This var char, something or something. Then comma, experience. Experience is? int, okay, int type. Like
this, how to specify? Where exactly I have specified this integrity constraint, not null I have specified
here, guys, okay? Create table employees, id int not null, name where care, experience int. So, for one
of the column, I specified this not null integrity constraint. Just because of this, while inserting the data,
how to insert the data? If I say insert into which table? Employees table, okay? Insert into employees,
values. Let us say I am giving 1 Arun 12. All the details I gave. First column details I gave as 1.
Second column details I gave as Arun. Third column details I gave as experience 12. Will this run or not?
Yes, this will run because id is given here. It is not null. So, this will work. This will be executed and these
details will be added here. 1 Arun and 12 will be added here. That is fine. but what if i say insert into
employees values to Varun. Okay. And here i am not going to give any value. For example, here i am
going to specify only id comma name i am going to give. Okay. Only I am going to insert the records into
the employees table for id and name column. But the third column that is experience, I'm not giving
anything. Will this work or not?
Yes, this will also work. Here two will come. And here Varun will come. Here what will come? Null will
come. Null value will come. Okay. Now another SQL statement I will try to insert for inserting the data.
That is employees. Insert into employees. Okay. So in the brackets I am giving name. comma experience.
Name comma experience values as tarun and experience is something like 7. Okay. Like this i am giving.
Insight into employees. Name comma experience values tarun comma 7. Will this work or not? This will
fail guys. This will give an error. Saying that the id cannot be null.
Here I am skipping the value from entering into the ID. Only name and experience I am trying to insert.
The data into the name and experience is going to be entered using this third statement where ID is
skipped.
So if null cannot come here guys, there is no possibility because while creating the table itself for this ID
column I specified the not null integrity constant. Here there is no possibility of null. So this record will
not be inserted and this particular statement will result in an error and you cannot move forward. So
guys, like this, this is one example of not null. One example of integrity constant is not null where if you
do not enter or if you do not insert any values into that particular column specified with not null, you are
going to get an error. So that is kind of rule or condition that you are putting on a particular table
column. These are nothing but the integrity constants.
Hope you understood what is integrity constants. And at same time, you can use the integrity constants
in the alter statements also. Two statements. while creating the table, while altering the table also. You
can, while updating the table also using the alter statement, okay? While creating the table, while
altering the table, okay? Using the alter statements. Then also, in the same way, you can use the
integrity constraint, okay? So, if the, when initially, initially when the table got created, you have not
specified the integrity constraint, let's say. But while updating the table, while modifying the table, you
can use the alter statement to provides this integrity constant, okay? So, integrity constants, if you want
to specify in the sql statements, can be used in create and alter statements, okay?
So, guys, hope you understood what are integrity constants. I have not explained any of these integrity
constants in a practical manner. So, not null, unique, primary, foreign, check, default. These are several
integrity constants we have. Each and everything i am going to explain in a practical way in the
upcoming videos. So that's it guys. See you in the next video session. Thank you. Bye.
So in this video session, I am going to explain and practically demonstrate how to use not null integrity
constraint. Not null is one of the integrity constraints. As explained in the previous video, there are
different integrity constraints.
Integrity constraints. And not null is one of them. So what are the different integrity constraints we
have? There are several integrity constraints. One is not null. Then we have unique. Unique integrity
constraint. Then we have primary key. Then we have foreign key. Then we have check and default.
These are the different integrity constants we have in SQL. The purpose of the integrity constants as
explained in the previous video is to specify a condition for a table column. For example, there is a table.
For example, there is a table like this. And this table has some columns like ID, name, some experience.
So if I specify any of this integrity constants to any of this column of this particular table, let's say ID
table, let's say ID column of this particular table.
For this ID column, I am specifying not null integrity. So, I am facing a condition guys. Integrity constraint
means condition. What is the condition? The condition is that this particular column should not accept
the null values. If you specify a particular column with not null, that means the column specified with
not null should not accept null values. Should not accept. null values. So, if you try to insert any null
values into this particular column, then you are going to get an error, guys. Okay? It will not accept. The
table will not accept if you try to insert any null values or if you don't want to insert any values also, that
is also a null value. If you don't insert any value under the id column, that record will also not get
inserted.
Instead, it will give you an error. Okay? So, in this video session i'm going to practically demonstrate how
to use not null integrity constant. Integrity constant means condition and not null means this condition
specified for a column for restricting the column from accepting the null values or restricting the column
from inserting the records without any values. Those are nothing but null values. Null means nothing,
right? So let me practically demonstrate. Here we have four databases. In one of the previous videos, I
created this QFox database. So let's use the QFox database, use QFox so that I can perform operations
under this QFox database. After use QFox got executed, then what we can do is we let's create a table,
new table, create table.
I'll call this table as EMP, EMP table. Okay. And in this EMP table, I'm going to create three columns, the
same three columns, ID, name, experience. Okay. id which type int, name, var cap, 15, okay? And
experience, experience again int, okay? Experience is int. Now, this is a normal way of creating the table.
But while creating a table, for one of the column, I would like to specify the integrity constant.
Say here, ID column is specified with not null integrity constant. How to specify that? Simple guys, while
creating the table, after id int, okay, after the data type of the first column, you have to specify not null,
okay? When you specify not null for one of the column that is id here in this employee emp table which
is of in data type, so what happens is once you once this table gets created with this kind of not null
integrity constant specified for this id column, okay, then the table got created, guys, okay?
The table got created. If you say select star from EMP, you will get the empty table, okay? Table without
any records you will get, okay? You see, a table, that is emp table, having the columns, ID, name,
experience got displayed here, but there are no records, okay? Now, let's try to insert the records. Let's
try to insert a normal record guys without uh i mean by providing all the required values. Insert into
EMP, values, one comma, ID is one, rn is name, and experience is two areas, okay? So, if i run this, If I
run this, it will insert the record. Without any problem, it is inserting the record. Insert statement got
executed successfully. Now again, if I run select star from EMP, now this time you will see a single record
under this table.
Under ID, we have one. Under name, Arun. Under experience, 12. That's fine. Now another record I'm
trying to insert. Insert into EMP values as this time, I don't want to insert all the three column values. so i
would like to insert only the columns that is EMP. I would like to insert id which should not be null that's
fine and name okay only name i'm going to skip the experience i'm not going to insert any value for the
experience column. Okay. For experience i'm not inserting anything. So here value should be only this
through two column values. That is two comma two comma one two comma one and run this. When I
run this again the Insert statement got executed successfully without any error.
And if I say select star from EMT this time, you will get two records. And second record if you observe
under the experience, what value got added? Null value. Okay. Can I add the same null value under ID?
Now, it's not possible guys because ID column, the condition is there like not null integrity constant is
specified here. That means ID will not accept the null values. Let's see. Okay. You have to get an error
guys. If you try to insert a null value without inserting any value into this ID, if you try to insert any
record, then you are going to get an error. Let's see that in action. Insert into EMP. This time only name
and experience I am going to provide.
I am going to skip the ID. ID I am going to skip. If you are going to skip means you are trying to insert a
null value into the ID. Values. Tarun. I am trying to give the experience as 7. Tarun comma 7. So, when I
run this, when I execute this, I will get an error guys. Okay. Run this. Error code field ID does not have a
default value. Okay. So, you cannot insert. You cannot insert. This statement is not going to work.
Similarly, if I try to insert into EMP values, okay, manually I am trying to insert null. Okay. Into this ID
column, I am going to try to insert manually null. Here, here if you are not specifying the column what
will happen indirectly we are going to insert the null value into the id that's already happened but here i
am specifically specially mentioning the null value here for insertion insertion and tarun comma
experience is 7 when i run this again we got an error because you cannot insert null into this id column
id column will not accept the null values okay either indirectly or directly if you try to provide the null if
you try to insert null into this id column
then we are going to get this kind of error like column ID cannot be null. You cannot insert null values
into this kind of columns because there is a integrity constant specified. That is a condition specified that
this ID column should not accept the null values. Not null means should not accept null values. So guys,
this is how we have to use not null integrity constraint in SQL statements. Hope you understood. Thank
you guys. See you in the next video session. Bye.
Hello everyone. Welcome to part 70 of SQL for BigNAT series. In this video session, I am going to explain
how to use Unique Integrity Constraint. So in this video session, I am going to explain how to use Unique
Integrity Constraint.
What is the purpose of this Unique Integrity Constraint? Unique Integrity Constraint when specified to
one of the column. Let's say there is a table here and there are different columns. And let's give some
names to these columns. ID, name, some experience. Like this, there are a few columns. If you apply this
unique integrity constraint, it's a kind of condition, guys. The condition you can apply to the particular
column. So, if unique integrity constraint is applied to a particular column like ID, then after creating this
table, if you are trying to insert some records, if you want to insert some records, this ID column, will
only allow unique values. For example, if i try to assign one, two, three here, all these numbers are
unique.
One is unique from two unit two is unique from three, like that. But if i try to assign one, then again one,
then this is a duplicate. One is not the uniqueness uh here this ones are not unique. Here, one is there.
Again, here, one is there. This one is the duplicate of this one. Okay? Unique means it should not be
duplicated this column which is specified with unique integrity constant will restrict the will restrict us
from inserting duplicate values into this particular column okay here one and one will not be allowed
because this particular id column is specified with unique integrity constant if i say two it's allowed if i
say three it's allowed because in the previous records unique okay our new values should be unique
from the previous records values so
this is how guys on applying the unique will get this kind of result now let me practically demonstrate
how to use unique so before i practically demonstrate there are several tables guys okay in this qfox
database as you can see here there are several tables which i have been creating from the lot of
previous videos i'm going to select everything guys okay i'm going to select all these tables which are
there which are created earlier in this qfox right click and then simply drop them okay So, drop now. All
the tables refresh. You see, all the tables got deleted. Now, under kfox database, there are no other
tables. Now, I'm going to create a new table in the kfox database. So, in order to create a new table
inside this kfox database, first i have to select this database.
Use kfox I have to say after selecting i can prefer i can create any table, I can use any table from this
database. now the table, now the database got selected. Now I'm going to create a table. How to create
a table? Create table, EMP. Okay? Create table, EMP. ID, inter Right? In one of the previous videos, I
explained where we have to use the integrity constants after the call after the column name, after the
data type, we have to specify. So here i will specify unique. For one of the column, that is id column, I'm
specifying the Integrity Constraint as, for this column, Integrity Constraint is specified as unique. Then
we have name, var char. Then another one is experience, right? Experience.
Experience int, like this we can write. Create table EMB, which has three columns, that is ID, name,
experience. And in this ID column is specified with unique Integrity Constraint. so if you are trying to
insert some data into this id column okay if you are trying to insert some data into this id column that
data should be unique okay the data should be unique it cannot be duplicated let's try to do so insert
into emp so i first i have to create this table guys okay select this statement and run it because the table
will be created table got created guys before inserting any records if i say select start from emp i will get
the empty table okay empty table without any records you see
Only columns are there. ID column, name column, experience column without any values. Now insert
into EMP values. I am giving one as ID, Arun, and experience as 12. That's fine. Then run this. A record
will be inserted. This is the first record. It will be inserted, guys. If I say select star from EMP, that
inserted record will be shown here. That's fine. Now I will try to insert another record, insert into EMP
values as 2. Will this be allowed or not? It also will be allowed. Varun. Let's say 7. Run this. Again select
star from EMT. Again another record got inserted. Because 2 is unique from 1. 2 is not a duplicate of 1. 2
is separate and 1 is separate. But if I try to insert some duplicate values into the ID column.
We will get an error guys. Because here if I say 1 again. and say tarunna and then 9. If I try to execute
this particular statement, here this record should not be accepted because this column is specified with
unique integrity constant which will restrict this particular statement for inserting a duplicate value into
the table. Already 1 is there, we are trying to again insert 1 which will not be allowed because of the
unique integrity constant. Duplicate entry 1 for [Link]. That's the problem. It's not allowing you.
Only unique values are allowed into the id column. If you try to give duplicate values, they will be
restricted. This is not possible. Now guys, one more thing is there.
Regarding this unique, there is one more thing. That is, here you have specified the unique at what
level? Column level. After providing the column name and its data type, you provided unique. But we
can even specify this unique for multiple columns at the table level. Okay. At the table level, we can do
that, guys. Okay. So, how to do that? So, again, we have to drop this table, guys, because i have to
create the table again. So, let me draw clear this stuff and simply go here. Refresh and here you will see
the earlier, just now created emp table. Right click on this and say drop drop the delete the table. Okay.
Now, I am going to create the table again. Create table.
EMP. A new table i am creating. That is create table EMP. id as int comma name as var char sum 15.
Okay. Comma experience as int. Like this i would like to provide. That's fine. Here three columns are
there. I have not specified any integrity constant for any of these columns. That's fine. But if i say comma
again and if i say unique of column level guys. Okay. I am providing the unique Integrity constant at
column level, unique of ID. I can say like this, unique of ID. What will happen? This is at table level. So
individually, I can give unique here. At same time, at table level, if I want, I have to provide like this,
unique of ID. Now run this.
This will work, guys. Only one column I gave here, unique of ID. Instead of specifying at column level,
unique keyword at the Earlier, at the column level, I specified the unique keyword. Right? Unique
integrity constant. But now, after completing all the columns, at the table level, I provided the unique.
Okay? I have not specified this unique for the particular thing. Unique of ID I specified. Now, run this. A
table will be created. Now, same thing guys. Same thing you will get. Insert into EMP values. Insert into
EMP values. 1, Arun, 2n this will be inserted. And another record i'm trying to insert, that is, insert into
emp values 2 comma 1 comma some 7. Will this be accepted? Yes, this will be accepted because here id
is unique.
Here is specified id as unique. That means here 2 is unique from 1 so it will be accepted it's not a
duplicate so it will be accepted if i say select star from EMP, We will get two records because we
inserted two records. They are fine. Now another insert into EMP values. Now again one. I am trying to
duplicate. I am trying to insert a duplicate ID into this table. Will this be accepted? No. Because here
unique of ID is there. It should not be accepted. Run this.
You will get an error saying duplicate entry. Fine. So again refresh and drop this table. So at table level
also we can specify the unique like this. The syntax will differ guys. Here only if you provide this unique
at the column level you have to say only unique here.
Okay. If you are specifying at the table level you have to say unique of column name. Okay. Unique of
column name. And one more advantage that we get by providing this unique at the table level is here
you provided only one ID. Only one column. But I can specify the unique to multiple columns. Unique of
id comma name okay unique of id comma name i can provide. Here two columns are there. Earlier
statements only one column was unique. But now two columns are unique. So let's create this table
now. Run this. Table got created. Now insert into emp values as 1 comma arun comma 12. Run this.
Okay. This is fine. Now, if I say inserted, it got inserted.
Select star from EMP. Run this. A record came. 1, R1, 2, L came. That's fine. Now, if I say insert into EMP
values 1, Varun, some 8. Okay. Will this work or not? Already 1 is there. will the one allowed or not?
Here I am saying unique of id comma name. Okay. That means these two columns together should be
unique. One Arun will be different from one Varun. Okay. One Arun is unique. One Varun is also unique.
Together. Together these two columns should work together guys. Okay. So if i run this it will not give
any error. You see it will be inserted. The reason here is here uniqueness is considered at the two
column level. Not a single column.
Both id and name should be clobbered together. That is 1 Arun is different from 1 Varun. Like this. 1
Arun is different from 1 Varun. Like this. If I run this, I already ran this and I got inserted. If I say select
star from emp, you can see that in the table 1 Arun, 1 Varun is there. They are not duplicate because 1
may be a duplicate of 1 but together 1 Arun, 1 Varun are not duplicate of each other. 1 Arun is different
from 1 Varun. That's why they are unique values only.
But if I try to insert something like this. Insert into EMP values 1, Arun, 9. Then what will happen? This
will give you an error. Already 1 Arun is already there.
Uniqueness is at the 2 column level. So, 1 Arun is already there. If you are trying to assign again 1 Arun,
this 1 Arun will be the duplicate of 1 Arun. Okay. So, it will not be inserted. Run this. You see, you got an
error saying duplicate entry 1 Arun. Okay. So, guys, uniqueness can be at the single column level and
multi-column level. Okay. In case of multi-column level, you have to club these two things and then
compare the uniqueness or duplication. So, guys, this is how we have to use unique integrity constraint
in SQL statements.
So, that's it, guys. see you in the next video session. Thank you. Bye.
Hello everyone. Welcome to part 71 of sql for beginner series. In this video session, I am going to explain
on how to use primary key integrity constraint.
So in this video session, I am going to explain how to use primary key integrity constant in the previous
videos, I have already covered two integrity constants what are they? I covered not null. And also I
covered another integrity constant that is unique. Now the third integrity constant is primary. What is
primary key integrity constant? Primary key integrity constant or condition is nothing but is a
combination of not null and unique guys. Okay. Primary when you specify a particular table column
when you specify a particular table column with this primary key integrity constant then that particular
column will have two conditions one is not null condition and unique condition we can assign not null
separately and unique separately right but when you assign primary it will contain two conditions
automatically that is not null condition and unique condition together is nothing but the primary key.
So if i say id here, name of the column here name here here experience so for this particular id column,
if i specify only one integrity constant that is not null if i only specify not null here what will happen this
particular column will not allow the empty or null values while inserting the records if you are not
providing the values for this id column that inserted records will be rejected by throwing the errors
that's what will happen this id column will not accept that accept the empty values or null values but
coming to unique if you specify only unique integrity constant to this id column of this particular table
then this id column will not allow the insertion statements to insert the duplicate values.
Only unique values will be as if you assign one, then the next insertion statement, you cannot again
insert one. You can only insert the two or five or something, okay? Which should be unique. The value
should be unique. At same time uh for unique, it should be unique. For not null, it will not accept the
empty values. They cannot be empty or null. Coming to primary key, it's a combination of both. When
you assign primary key integrity constraint, For example, if you are assigning or specifying this ID column
with this primary key integrity constant, then this ID column will not allow the null values or empty
values. At the same time, it will not allow the insertion statements to insert the duplicate values.
Now, let me practically demonstrate how to use primary key in SQL statements. Let's go here. So, let me
select this QFox database. Under this, I am going to create some table and then demonstrate. Use QFox.
run this. qfx database got selected. Now I can create some tables under the qfx there are no tables here
for now i am going to create a new table create table table name that is EMP, let's say, and ID, column
name, int. This one i am going to specify as primary key. The first column i am going to specify as
primary key, guys, okay? Comma, here integrity constant is provided. Similar to the not null and unique,
you have to specify the primary key integrity constant at the column level also.
ID, name, var char, sum 15 and then experience, experience int again. Like this. Now when I run this, this
particular EMP table will be created with three columns. ID column, name column, experience column in
the same way I explained here. ID, name and experience. And for ID column, we are specifying the
primary key. Here you see primary key is specified. Run this. When I run this, the table will be created.
Table got created with the three columns. How to find out how many columns are displayed, created?
Select star from EMP. When I run this statement, it will give me the empty table with columns, column
names. Empty table is their ID, name, experience. Okay. ID, name, experience. Fine. Now, now I'm going
to insert some records into this EMP table.
Insert into. EMP values. 1 comma. Arun. Comma. Followed by experience as 12. Let's say. Done. When I
run this. You see. The record got inserted. If I say select star from EMP. That inserted record. First
record. 1 Arun 12. Is getting displayed under this column. That's fine. Now I am trying to insert another
record. Insert into. EMP values. Let's say this time I am going to insert again 1 over 12 or 7. Will this be
inserted or not? Will this statement be executed or not? If I execute, this statement will result in an
error because I have mentioned primary key for the int id column. So primary key means not null plus
unique. Here 1 is not unique. 1 is already there. It is a duplicate.
So it should be avoided. Run this. You will get an error saying that Duplicate entry 1 for key. Duplicate
values will not be allowed by the primary key. Integrity constant specified columns. Now this is not
possible. This was not possible. Still only one record is there. The first record is only there. This is not
inserted because we got an error like duplicate entry. Now again I am going to insert something. Insert
into EMP. This time I am trying to skip the ID column value. So only I am going to give what name and
Experience. Only name and experience i am trying to insert. I am going to skip the id column value. That
means null value will be inserted. Simple. Okay. Indirectly. So here i am going to give two i mean two will
not be there.
Sorry. Here name and experience i have to give without id. So here i am going to give something like
tarun 9. Will this be inserted guys? No. This will also not be inserted. We will get an error because id
column is a primary key. That means it cannot be null. It's not null. Okay. Not null plus unique. Both
combination. Both conditions. Even though. Okay. If you skip any ID column value. That means you are
trying to insert some null value or empty value into that ID column. So that will not be allowed guys.
Okay. Because ID column is specified with primary key. And it cannot be null. And it cannot be duplicate.
So both conditions should be satisfied. Run this. You will get an error saying that field ID doesn't have a
default value.
Some value should be provided for ID. You are only inserting the name and experience. Along with that
you have to insert id. Then only this statement will be executed. Otherwise, you see when I run this only
one record is there. First record is only there. This has not worked and this has not worked. These two
statements have failed. Because here I am trying to insert a duplicate value into the id column. And here
I am trying to insert nothing into the id column. I am going to insert nothing. Only name and experience I
am trying to insert. That means empty and null value I am trying to insert. That is also not possible. So
guys, primary key means unique plus not null.
[Link] conditions will be there. Now, so far, so far, I have specified the primary key at what level? I
specified the primary key at the column level. But I would like to, can i specify the primary key at the
table level? Yes, guys. We can do so. Okay. For that, what i will do is i will remove all this stuff. I will say
drop table EMP. I will delete. i'm going to delete the table, okay? So drop, I mean, completely deleting
the table drop table emp table got deleted. It's not there now. So clear this stuff now right then i try to
create another table create table emp the new table, guys. ID, int, comma, name, where care, and
experience, in Here, I have not specified any primary key.
at the column level. Any of these columns doesn't have the primary key. But if i say comma here, at the
end of the columns, after all the columns are done, if i put a comma here and say primary key, off.
Okay? Inside the off, I have to specify the columns let's i will say id. Only for id, the primary key will be
there. Okay? But, so what will happen? The same thing. Whatever I showed you, right, the same thing
will happen again. so try to do that try to execute this a table will be created uh here primary key is
specified at the table level and only one column is primary key here that is id column first column so
same things will happen guys whatever i explained so far will be the same again the same thing i have to
explain select start from emp values sorry let's start from emp first of all so run this empty table without
any records okay only columns are there now
insert into emp values 1 comma arun comma 12 if i run this, what will happen? This will be inserted
without any problem. This is the first record. Does it have any problems? Okay. Again, if i say insert into
emp values, again 1, varun and some 7 what will happen? Will this be inserted? No. Because ID is a
primary key id is a id column is a primary key. If you try to insert, duplicate value, it will be rejected. So
this statement will give an error. Error will be displayed like duplicate entry, okay? This is not succeeded,
guys, okay? Run this, only one column, one record will be there as usual, okay? That has come from the
previous statement.
Now, insert into dmp values sorry uh here i will say name, comma, experience.
Only, I am trying to insert the records and insert the data into the which which columns of the table,
only name and experience. I am skipping the id column. Now if I say values, name is, let's say Tarun,
experience say 9. Will this be inserted? No guys, this also will not be inserted because id cannot be null.
Id cannot be null, not null. Id is not null. Primary key means not null and unique. So here this got
rejected because of the unique constraint, right? So 1 cannot be duplicate. Already 1 is there, you
cannot insert 1 again. Here the problem is, You are trying to insert a null or empty value into this ID by
only specifying or inserting the records into the name and experience.
This will also not work because there's a possibility of null. So, field ID doesn't have a default value.
Without ID, you cannot insert the records.
Now, this is what will happen, guys. This is what. Now, again, I'm going to drop the table. Drop table
EMP. Run this. Table got deleted. here this. Again, create the table create table emt again id int and then
name var cap of 15. Then experience. Experience is int again okay like this now again i am going to use
primary key at the table level. How to do that? I have to, after the columns, I have to say comma primary
key of primary key of, here i'm going to specify two columns this time. Not only id but also comma
name.
Okay? Now, what are the primary keys? Not only id but also the name is also a primary key. Two are
primary keys. Let's try to insert. I mean create this table first. Create this table first. The table got
created here as you can see guys. Now, let's try to find any records. No records will be there. by default,
so select star from emp will result in only column names without any records under it. So when i do so,
column names without any records came. Now I am trying to insert some records. Insert into emp
values. Insert into emp values here 1 comma arun comma 2l i am going to give. First record i am trying
to insert. This will get inserted without any problem okay so again if i select select star from EMP, 1,
Arun, 2L.
1, Arun, 12 got inserted into this table. That's fine. Again, if I say insert into EMP values, here, if I say 1,
Varun, 7, will this be inserted or not? Will this be inserted or not? This will be inserted, guys, because
primary key is at 2 column level ID name. Here one plus Arun is not same as one Varun. Okay. One Arun
is not same as one Varun. Individually one is same. But here combination we have to check guys. Okay.
ID comma name is there. Primary key means unique. Unique means check that two levels. Okay. Two
column levels. Two column level. That is here only one will not be considered for checking the
uniqueness. Only ID is not considered. ID plus name will be considered.
Two columns will be considered for uniqueness. finding the uniqueness. Here one Arun is different from
one Varun. So this will get inserted. Run this. You see it got inserted and if I say select star from EMP you
see two records are there. Again if I say insert into EMP values. This time if I say one Arun. Will this be
inserted? Can I insert this guys? It cannot be inserted because one Arun is already covered here. This
value cannot match another value. Duplicates will not be allowed. Duplication is checked at the Two
column level, not single column. One Arun, one Arun. Both are same. Okay. When you run this,
duplicate entry one Arun. Okay. Will come. You cannot insert the duplication at the column level.
Okay. Two column level. Now, next thing is, next thing is, this is not possible. Next thing is, can I insert
null values? I mean, can I skip something into this ID or name? Let's find it out. Insert into EMP. I am
trying to skip ID guys. Name comma experience. Values as name is some Tarun and some experience is
some 10 years experience. Will this be inserted or not? No guys. We will get an error. The reason for the
error is ID cannot be null. Right here two columns are not null. ID column is not null and name column is
not null. So if you skip ID that will give an error. So, run this. Error will come unknown column uh xp
sorry i have to give the proper name here guys xp reins okay now run this.
We'll get an error saying field id does not have a default value. ID cannot be null or empty. That's what it
is saying. What if i give something like, a same statement. Same statement. This time i'm trying to insert
id comma experience. I'm skipping the name. Okay? I'm trying to skip the value. i am trying to enter null
value into the name. So here, column, here primary keys for both id and name. So if i skip id, it's giving
an error. Similarly, if i skip name also, it will give an error, guys. Okay? So if i try to do so, like here i give
something like uh three comma experience only right uh 10 3 comma 10. if i try to do so, idea and
experience i am giving but i am not giving name.
But name is also a primary key here. That means it cannot accept the null values run this you will get a
error here. you'll get an error saying field name doesn't have a default value. So guys, primary key
integrity constraint can be specified while creating the table at the column level or at the table level.
Okay. If you specify this primary key integrity constant at the table level, you can not only specify for
only one column, but you can specify multiple columns. Okay. For which unique and not null conditions
will be applied for those columns. Okay. So guys, This is how we have to use primary key integrity
constant. So that's it. See you in the next video session. Thank you. Bye.
Hello [Link] to part 72 of SQL for beginner series. In this video session, I am going to
explain on how to use foreign key integrity constraint in SQL statements.
So in this video session, I am going to explain how to use foreign key integrity constraint. There are
different integrity constraints that we can use in SQL statements and foreign key is one of them. In the
previous videos, I already covered few of the other integrity constants like not null, unique integrity
constraint, followed by primary key. All these three integrity constants are already covered as part of
the previous videos. In this video session, I am going to cover The next integrity constraint that is foreign
key. So guys, let's get started. In order to understand this foreign key, we need to have two tables.
We need to have two tables. This table and another table. Maybe I'll start here like this. In order to
understand this foreign key, we need to have two tables. Let's take an example tables. Let's say this
table name is employee table. And this table name is salary table. Okay. We have two tables. One is
employee table. Another one is salary table. And there should be a kind of relationship between these
two tables. That is one table need to depend on another table. Which table will depend on other table?
Salary table has to depend on employee table. Here employee table will become a parent table. We
need to make the employee table a parent table, whereas the salary table as a child table. This one
should become a child table.
In order to understand this foreign key, we need two tables. That is, one should be a parent table, other
should be a child table. That means child should depend on the parent, right? So, that kind of
relationship we are going to create. Fine. And one more rule here is, these two tables should have a
common column. These two tables should have a common column. So, let me create some columns and
one of the column is going to be a common column. Let us say there are three columns in the first table
that is employee table which is going to be the parent table. We are going to make the employee table
as a parent table. ID, name, experience. Fine. ID, name, experience. These three columns are there in
the parent table that is employee table.
Coming to the salary table, we only have let's say two columns. Two columns. One is ID column. Other
one is salary column. So what is the common column here? Can you see what is the common column
between these two tables? ID. ID. This is a common column. Okay. Name can be different guys. Here ID
is there. Some other name can be there here. But the data type should be same. Okay. For example, this
particular column is of type int. Then common column should have the data type as int only. Okay. Even
though the name, you can say i ide also okay not a problem that's not a problem name can be different
but data type should be same. That is going to be called as a common column in case of
foreign key tables, okay? Foreign key related explanation tables. you should have a common column
with having different names, can have different names. These names, it's not compulsory to have the
same names for this common columns, but their data type should be same. This into data type, if it is
there here, the common column in the other table should also have the into data type, but name can
differ. That's what you have to remember, guys. Fine. Anyhow, in this example i am going to take the
same name, okay? It doesn't matter if they have the same name or different name. But data type should
be same. Fine. Just keep that in mind. Now, there are two tables. One of the table is the employee table
which is going to be the parent table.
Another table is the salary table which is going to be the child table. Which table is going to depend on
which table? Salary table is going to depend on the employee table. Okay. That should be our
understanding and they have a common column. That's fine. Now, just remember one thing blindly
guys. That is parent table. Okay. In parent table, we have to specify the common column. What is the
common column here? ID is a common column. We have to specify the parent table common column
with primary key. Primary key. Parent tables column, common column should be specified with primary
key. You can remember something like this. P, P. Okay? Parent table, primary key. Both starts with a P.
Okay? Parent table should have the primary key.
You remember that. Whereas, The common column in the child table, okay, should be specified with
foreign key.
Okay. Child table, foreign key. Parent table, primary key. PP. You have to remember that. Okay.
Sometimes we may get confused, right, child table like that. Okay. So, it's better to remember like
parent table is going to have the primary key because both parent, P will be the first letter in the parent
and P will be the first letter in the primary key. So, they match and you can remember like that. Fine. So
these are the rules guys. Okay. These are the rules we have to follow. And there are a few more rules. A
few more rules is once you, once you like create this parent table and child table and once you have this
primary common column in the parent table as the primary key and common column in the child table
as a foreign key, then next steps are something like this.
This table is going to depend on this table. Okay. Which table is going to depend on which table? child
table. In our example, child table is salary table okay salary table is going to depend on, depend on
parent table. In our example, parent table is employee table okay employee table the actual details,
main details will be there in the employee table and the corresponding details will be there in the salary
table like that that's why child table is going to depend on the parent table. Fine. Now, I will insert some
records into this parent table. I will insert few records into the parent table. Let's say here I will give the
ID as 1. Here ID as 2. ID as 3. Same time name as Arun.
Here Varun. And here Tarun. Here experience as sum 12. 7 and 9. Like that I have filled up this.
employee table. That's fine. Now, you have to remember few rules, guys. Okay? Here, child table is
going to depend on the parent table, I am saying. What are the rules that we are going to get here? The
first rule is, rule one after making the child table dependent on parent table, the rule one is, the rule one
is, let me drag it here. Rule one In order to insert data into the child table data inserted into the child
table should have the same data of the should have the same data of the common column of parent
table. What does this mean? There is a common column, right?
ID is a common column here. In both these tables, ID is a common column. If you are trying to insert,
after inserting the records into the parent table, if you want to insert the records into the salary table,
let's say you want to insert some records here into the salary table. Then what's going to happen here is
if you try to insert some record, let's say you try to insert the ID as 1 and you are giving salary as 14
lakhs. This will be accepted. this is accepted because this one is already there in the common column of
the employee. Here one is there. That's why one is accepted. If I try to give something like nine here.
Okay. Here one two three are only there in the parent table.
But here you are trying to give some other different id that is nine which is not there in the parent table
this is not going to be accepted okay nine is not going to be accepted guys because salary table which is
a child table is going to depend on the parent table. Okay. So, It will be validated according to the
common column. The values that are there in the common column of the parent table are only allowed
in the common column of the child table. If you try to add any other value which is out of this parent
table common column, you are going to get an error.
This is the first rule you have to remember guys. 9 is not allowed here.
9 is not allowed here. Because here only parent table common column has 1, 2, 3. Not 9. Fine. Now, let's
say the parent table has this one two three all these details and child table has this one 14 lakhs. It's a
package. Okay. Like this, up to this it is there. Now, second rule is, second rule. Since the child table is
dependent on the parent table, you cannot delete the records. Okay. In the parent, table which have
associated data. Okay. Associated data in the child table. What does this mean? Okay. Just move it
there. Fine. Rule 2 is you cannot delete the records from the parent table having the associated records
in the child table. Let me explain it practically. Here, I mean, by looking at this diagram, let me explain.
Here, is there any associated data related to parent table in the child table? Yes. This 1 around 12 has
associated data that is 1, 14 lakhs in the child table. Okay, these two are related right here one is there
here one is there this is an associated data in the child table of this parent table. Now if i try to delete
this, if i try to delete this first record, this will not be possible without, okay, because there is some
associated data in the child table related to this parent record. Okay, if there is some data in the child
table which is related to the data in the parent table, then you cannot delete this. This is not possible.
Okay, you cannot delete this record.
If you try to do so, you will get an error, guys. You are going to get an error. Okay? And how to do that?
Then if i have to really delete this record, which is having an associated record, first i need to delete this.
Then only i can delete this. Okay? First the dependent, okay, child table record should be deleted. then
after, you can delete the parent table record. These are all the rules, guys, okay? You have to remember
all these things. Let me recap at a high level again, okay? So, in order to understand the foreign key, we
need two tables. One should be a parent table, which will have the master kind of data, whereas the
other one is a child table, which is going to be having the dependent kind of data, okay?
So, we have the parent table, child table. In this example, we took employee and salary. And another
rule is both these tables should have a common column. Here, we have a common column. Here also we
have a common column. Here data type should be same. It's not compulsory that the name of this
column should be same. That's another thing. Then the next thing is we need to specify this primary key
for the common column in the parent table. P and P should match. Parent table should have the primary
key for the common column. Whereas the child table should have the foreign key for the common
column. These are the another rule. After this is done, the relationship between these two tables will be
established in such a way that the child table is going to depend on the parent table.
After establishing this, after specifying this primary key for the common column in the parent table, after
specifying the foreign key for the common column in the child table, a relation will happen between
these two tables in such a way that this will become a child table, this will become a parent table, and
the child table is going to depend on the parent table. Okay? Because of this case. Then afterwards,
now, you can insert any number of records into the employee table without any problem. Okay? Here I
inserted three records with different sets, types of data. Okay? Sets of data. Fine. After inserting the
record, when you try to insert, there are few rules coming after because of this dependency, there are
few rules coming.
That is, when you are trying to insert the records into the child table, The child table records should
match the common column values that are there in the parent table. For example, if you try to insert
here 14 lakhs, it will be accepted because this 1 in the common column of this child table is matching
with the 1 in the parent table. Since 1 is there in this list, 1 can be accepted. If I try to give 9 here, it will
not be accepted because 9 is not there in this common column values of the parent table. So, it will not
be accepted. That is the first rule. Second rule is, if I try to delete any record directly from the parent
table, which has some associated record in the child table.
Here, 1 Arun 2L has 1 14 lakhs as an associated record in the child table. So, if I try to directly delete this
without worrying about this, this will not happen. You will get an error. So, how to delete this? First, I
have to delete the associated record in the child table. Then only I can delete the record in the parent
table. So, first i have to clear the child dependency.
Then I have to delete the parent. Like that, okay? Parent record. And one more thing. There is one more
case, guys, okay? One more case is on there's something known as on delete cascade option on delete
cascade option is there, guys. You have to understand this on delete cascade if i use this on delete
cascade while creating this parent and child tables using this primary and foreign key,
If I specify this onDeleteCascade, what will happen is, if I try to, the second rule, onDeleteCascade is
related to the second rule, where if you try to delete the parent record without deleting the associated
record in the child table, you are not going to delete, right? But if you provide onDeleteCascade while
specifying the primary and foreign key, what happens is, even though if you try to delete the parent
table, automatically the associated child table record will be deleted, okay? go here, manually delete
this and then we can delete this. But if you provide on delete cascade if you delete this record,
automatically this record will also get deleted.
Okay? It will not give you an error because you have manually specified on delete cascade in that
creation statement.
So guys, this is theoretical part. Whatever I explained so far is a theoretical part. Let's move into the
practical mode and understand in detail. Fine. So let me open my workbench where i i would like to
explain this concept of foreign key. So it has to launch it will yeah it's launching guys. Let's give it a some
time. Yeah, Workbench has been launched and uh we are going to connect to the mysql server from this
workbench client. I have to give the password that is root as explained in the previous videos. I have
given root password to connect to the mysql server. from this mysql workbench. Now, guys, we have
four databases here uh out of which four databases, this is the database i have created in one of the
previous videos, whereas these three other databases came by default in the, with the MySQL.
When I installed mysql in my machine, these three databases came by default. I have not done anything
for getting this database okay? They came by default. Now, in this, anyhow, in this video session, I am
going to use this qfox database, which i have created in the previous videos. Fine. so how to how to
create i want to create some tables okay already some table is there that is the emp table is there under
the tables of this qfox database but i don't want to use this one i want to use another table for that
that's fine but in order to create a table under this qfox database i have to first use this qfox i have to
run the statement sql statement like use qfox and run this when i run this this that database that is qfox
will get selected now on i can perform
All operations on the existing tables are, I can create new tables or modify tables, whatever it is, under
the GFox database directly. So now, I am going to create a table, guys. Create table. Which table I am
going to create? First, I would like to create parent table. I am going to create, this is a comment, guys.
Double hyphen, some text means this is a comment. It will not be executed as explained in one of the
previous videos. Create table. What is the table name? I will give it as employee table. Here, whatever
the table i created, employee table, I'm going to make this as a parent table okay by by following these
rules they are like uh creating common column and specifying with primary keyword, it will become a
parent table, okay?
So anyhow, employee is a parent table. If you also think generally, here, id int, then name varchar
sum15 comma experience again int. like this, I created. So, if i have to make this particular table a parent
table, okay? Common column, I have to decide first. I'm going to make the common column, another
table also i'm going to create. Let me create otherwise. I'm going to create a child table for this above
parent table. I'm going to create the child table. First, let me run this first okay fine let's not run this
because i have to do some more things there. Okay? This is going to be a parent table guys create table
employee don't run this for now. Okay? and I am going to create the parent child table like create table
salary.
Here ID again int and then I am going to give the sal because table name is salary so I am giving column
name as short form for salary is sal, like int sal int like this. Now, now, as per the rules, we have to cross
check few things. That is the parent table and child table. should have a common column. Is there any
common column? This is a common column. I'm going to choose ID. ID. Okay. That data type should be
same guys the name name of the column can be different. That's fine. Okay. Okay. Then second thing is
the parent table should have which which key. I mean in uh what is that uh the parent table should have
which integrity constant you can say.
Okay. Parent table should have the primary key integrity constant, okay? If you want to remember
which table should have primary, just remember here, parent. Parent starts with P. Primary key also
starts with P. So, parent will have primary key. So, for which column i have to specify this primary key?
For the common column in the parent table, I have to specify the primary key. So, here, after int, I am
going to specify the primary key. This is done. Next thing is, child table should have which Integrity
Constraint. It should have, child table should have foreign key. And to which column I have to specify it?
The same common column in the child table I have to specify the foreign key. So here it's not like this
guys.
This is not like this. I will explain how to provide the foreign key. Primary key can be provided like this.
After the column name then data type you can provide the primary key but foreign key should be
provided in a different way where you have to say comma foreign key off you have to say off Okay.
Which column? ID column. This after all the columns are done you have to start the foreign key and you
have to specify the column that you want to make that as foreign key. Then you have to say references.
Okay. References. So, Yes. References in the employee table. EMPL. Okay. Employee table. Which
column? ID column. Okay. Okay. There is something i am doing wrong. Foreign key of id references.
if Okay. References. Is it coming? Yeah. Now it's. This was. Spelling mistake. Okay. Small spelling mistake.
So references. There was spelling mistake. Now it's good. Employee of ID. So that's why we can say this
parent table. Another name for parent table is reference table. Okay. A child table can refer to a parent
table. That's why we can call the parent table as a reference table. Okay. And here the keyword is also
same. References. Foreign key of ID. in this child table, for the common column, you selected the id
column as the id common column as a foreign key. And this foreign key is going to refer to the refer to
the common column in the employee table okay which is specified with the primary foreign key is going
to refer to the common column in the parent table.
Here, references stands for reference table okay references reference table, that is parent table.
Employee, employee is a parent table. So, this statement will make the parent and child guys okay till uh
like before i added this foreign key statement, this was a normal table, this was a normal table. Once I
added this foreign key id from the child table, references the parent table ID, then the connection has
been established and the relationship has started, like, employee is going to become the parent table
and uh this salary table is going to become the child table. Okay? Okay. This foreign key is going to
connect to the common column of the parent table. That is primary key specified column of the parent
table. Okay. Fine.
Now next what? Next is we have to execute this statement. Okay. Since we have specified the primary
key, foreign key and we have connected this foreign key to the primary key of this parent table.
Everything is done. Right. Now what I can do is I can execute this statement. Run this. Once I run this
statement. table got created. Okay? You can see. You can confirm whether the table got created like the
select star from employee. If you say like this, it will give you an empty record but columns will be
displayed. Okay? So, column name is ID, name, experience, employee table column name is column
names are ID, name, experience got displayed here without any records.
Now what i'm going to do next is i'm going to insert the records into the parent table. Can I insert or
not? I can insert without any problem. Okay. This is a master table for a parent table reference table or
master kind of table. you are free to insert any type of records into this parent table. Okay. So, insert
into. I am inserting the records into the parent table. That is employee table employee employee values
one comma that means like uh insert them fast bit fast.
So, one Arun. 12 years of experience. ID is one. Name is Arun. Experience is 12. Similarly, insert into.
Employee values. Two comma. One. experience is 7. Then insert into employee values 3 comma Tarun.
And experience is 9. Like this. Okay. So, let me run these three statements so that at a time three
insertion records will be added to this uh employee table. Run this. They got inserted. Now, if i say select
star from employee i'll get the employee table we're having the columns id, name, experience with
three records one two three 1, 2, 3, 12, 7, 9 experience. Okay. Now, next thing is, now this is fine. Now,
let's try to insert the records into the child table. Now, let's try to insert the records into the parent table
insertion is done guys.
Okay. Now, child table insertion I am going to do. Insert into salary values. If I say 1 comma 14 lakhs, will
this be accepted or not? This will be accepted guys because this one common column ID where you are
trying to insert 1 is already there in the employee table. Since 1 is already there, it will be accepted by
the child table also. So run this. It got inserted. If you say select star from salary, you can see that it got
inserted 1 for till next.
Now if you try to insert another record, insert into salary values as 9 comma Some 9 lakhs. If I try to
insert this, what will happen? It will not get inserted because this 9 id is not there in the common
column of the parent table.
You see only 1, 2, 3 are there. Only 1, 2, 3 are allowed in the child table. But 9 I am trying to insert, you
will get an error guys. You see you got an error saying that cannot add or update a child row if foreign
key concept fails. You cannot insert something that is not there in the common column of the parent
table. Fine. Here 9 is not there in the common column of the parent table. So it cannot be done. You can
insert the normal values like insert into salary. Okay. Values as like a 2 comma. 2 comma. Let's say some
6 lakhs. Okay. 6 lakhs. This is possible. 6 lakhs is possible. 14 lakhs is possible i mean sorry uh one is
possible, two is possible, because one two are already there, right?
So, if i try to insert, it will be inserted, again because this two is already there in the common column of
the parent table. Apart from this one two three if you try to give anything, that will not be accepted fine
uh that is one rule you have to understand.
Second rule is, I would like to delete this record for which associated record got inserted already, okay?
So, if you run this, here 1, 2 is already there. And if you try to delete this record, okay, having the ID as 1.
In select star from employee also, we have 1, 2, 3, okay. If I try to delete this record, 1, R1, 2, L, which is
having an associated record in the child table, that is 1, 14 lakhs.
We cannot do that, guys, okay. Let me try. We will get an error. Delete from which table? Employee
table. where id is equal to 1. If I try to do so, this record, which is having the id as 1, has associated
record in the child table with 1, 14 lakhs value. Hence, this statement will not work. If you run this, you
will get an error saying that you cannot delete or update a parent row.
Foreign key constant fails. This is a condition of the foreign key. All these dependencies are happening
because of the foreign key. Foreign key has kept a condition where You cannot insert some records into
the child table which are not associated with the parent table records. Second thing is, you cannot
delete the parent records directly which have the associated records in the child table.
These rules are coming just because of the foreign key. This is the concept of foreign key. This is the
condition that foreign key is applying on your parent and child tables. Now, this is not happening. When
I try to delete the record which is having an associated record in the child table, parent record is not
getting deleted. How to delete? First, I have to delete this record. Okay. First, I have to delete this
record. So, if I say delete, delete from salary where ID is equal to 1. I can delete from child table without
any dependency on the parent. I can delete this from the child. Run this. You see, the child record got
deleted.
If I say select star from salary, I will not see 1.
Delete from employee where id is equal to 1. Got deleted. ok Earlier it was not deleting because there
was associated record in the child table. But after deleting that associated record from the child table,
we can delete the parent table record without any problems. Now, I am going to drop. ok So what I am
going to do is I am going to drop this [Link] if I say drop, I'm going to drop the child table here. Okay,
simple. Drop table. Table name salary. So now before dropping it, if I refresh, I have the salary table
here. But let me run this drop.
So after deleting the salary table, the salary table got deleted. Now I'll freshly create the salary table.
This time, while creating the salary table, I'm going to specify create table table. Salary, ID int, sal, int,
foreign key ID, references, employee ID. And here i will say, on delete cascade. On delete cascade. Like
this i will say. And I will create the child table like this. Okay. When I run this, child table got created.
Okay. This time, I specified this keyword known as on delete cascade.
That is the difference. Now, If I run this select star from employee on the parent table, I am getting this
two records. 2 Varun, 7 is there. 3 Tarun, 9 is there. In the parent table, we have 2 and 3 Varun, Tarun, 7.
2 and 3 Varun, Tarun are there. Now in the child table just now got created, I will insert this record.
Insert into salary value 2. It got inserted. Now if I say select star from salary. And also one more thing I
will do is insert into employee values. I will get back everything. Okay, so now if I say select star from
employee, so it has 1, 2, 3, Arun, Varun, Tarun. Okay, 1, 2, 3 records are there. IDs are 1, 2, 3 are there.
In the child table, we have select star from salary. What is there? Only one record is there. I will get this
first record also now. Okay, so now in the child table, we have 1, 2, 14 lakhs. So now, since I created this
table with on delete cascade, if i try to delete any record from the employee table where id is equal to 1,
which has an associated record in the child table, right? Here, 1 around 12 is there in the parent table. It
has associated record that is 114 lakhs in the child table. If I try to delete this table directly, will it be
deleted or not? It will be deleted, guys. At same time, this 114 lakhs will also get deleted because of this
option, okay?
Hello, everyone. Welcome to part 73 of sql for beginner series. In this video session, I am going to
explain on how to use check integrity constraint.
So, in this video session, I am going to explain how to use check integrity constraint. So, in the previous
videos, I have explained the other integrity constraints like not null integrity constraint, then unique
integrity constraint, primary key integrity constraint and foreign key Integrity Constraints. All these four
Integrity Constraints are already explained as part of the previous videos. In this video session, I am
going to explain the next Integrity Constraint that is Check Integrity Constraint. So, what is the purpose
of using this Check Integrity Constraint? Check Integrity Constraint when applied to the table like this.
When you apply this Check Integrity Constraint to a table, let us say there are few columns here. like id
column, name column, and experience column. Now, if you apply this check integrity constraint to one
of this table columns, say experience, okay? Check integrity constant is applied to the experience in such
a way that by using this check integrity constraint, you can provide a condition to this experience
column. That is, experience should be greater than five okay? Check experience. greater than five like
this kind of conditions you want to provide. If you want to specify this kind of conditions to the
experience column, then we have to use check integrity constraint. So not only this condition guys, any
condition like a lot of conditions.
I'm going to do some examples anyhow. So with the help of check integrity constraint,
we can check few conditions like this on the particular columns. Now what will happen when you try to
insert some records into a table, which is having a column, having this check. Integrity constant
condition, then. Let's say this is an employee table and you are trying to insert some employee records,
having some id name and experience if you try to insert the employee details having the experience
greater than 5 let's say 10 if you try to insert 10 here this will be accepted by the experience column. But
if you try to insert something like 3 or 5 these two values will be rejected, okay? This cannot be inserted.
Three, because the check condition here is experience should be greater than five. Then only it will
accept the record. Otherwise, here phi also is phi is not greater than five. So this also failed. So if you
want to provide that that kind of conditions on a particular column, we have to use check integrity
constant.
Let me practically demonstrate, guys. So here we have four DBs, and i would like to work on the tfx by
creating a new table, guys. In order to create a new table under this tfx I need to select this DB out of all
the remaining DBs. How to use that? How to do that? Use QFox, I have to say. Then run this. The QFox
database will be selected.
Under this, there are a few tables, guys. EMP, EMP3, and all those stuff. A lot of tables are there. But
what I'm going to do is I'm going to select everything and say right click and drop. I'm just going to drop
all the tables. Let's see all the tables. Yeah, all the tables got dropped, guys. Okay. So now we can freshly
create the tables. Let me create a table like create table. Create table EMP1. Okay. ID as name. I mean ID
as int. Name as var char of some size. Then experience. Experience is int. Followed by this, I will provide
a check condition. Check whether, okay, experience is greater than 5. Like this, I have to write. Check
experience. I have to put this inside a circular brackets.
So, that is important. Check of experience greater than 5. Check integrity constant look like a function
syntax here. It should be started with circular bracket and ended with circular bracket. In that, we can
provide the condition. This is going to be the condition inside this check kind of integrity constant. Like
this. This is the syntax guys. Create table EMD1 ID int name worker. for the column, you want to provide
this uh integrative constant like check, okay, with a condition. You have to provide the check with the
circular brackets and inside the circular brackets of the check, you have to provide the condition. Now
run this. A table will be created, EMP, with this kind of condition. Now table got created. I will say select
star from EMP1.
When I say select star from EMP1, the table will be displayed, but uh you can only see the columns of
the table like ID, name, experience, there are no records. Now let's try to insert some records. Insert
into emp1 values 1 comma arun comma 12 will this be inserted or not? Yes, it will be inserted because
here the experience is greater than 5 itself. 12 is greater than 5. So it will be inserted without any
problems. Run this. It got executed. Now select star from EMP1. You see the inserted record is there
here. Now, another insert statement i am writing. Insert into emp1 values as 2 comma varun comma 3
will this be inserted? Can this be inserted no this this record will be rejected from insertion because the
experience i am providing s3 but here check condition is experience should be greater than 5, but 3 is
less than 5.
Okay, 3 is not greater than 5. So, I am going to get an error. Run this. You see, check constant is violated.
This constraint condition is violated. That's why this record is not inserted. If you say select star from
EMP, only one record will be there. That was inserted by the first insert statement. Now if i say insert
into emp1 values as 3 comma current comma 5. Will this be accepted? This will also not be accepted
because here the experience should be greater than 5. It's not equal to 5. Greater than 5. But 5 is not
greater than 5. So this also will be rejected. So Run this. You see, it got rejected. Check constraint EMP is
violated. Experience should and must be greater than 5.
Then only it will be allowed. So, to specify such kind of conditions, then we have to use check integrity
constraint. Another example I would like to give you guys. I am going to create another table. Create
table EMP2. Then id as int. Location as var cap. Location var cap. Now, I would like to provide the check
condition to this location. So, after this data type, I will say check. Check off. Okay. Check off. Inside this
check function kind of thing, you have to write down the condition. Condition is location should be in
location should be in either India or USA or UK. if you try to give any other country, okay, apart from
these things, then you are going to, the record will not be inserted.
Let's say this is a thing, okay. Check table, two columns are there. ID and location are the two columns.
And for the location column, I created a condition, check condition, saying location should be in Spain,
USA. Or else you can see country here, okay. from which country this employee is from like that okay so
for this, you have to say country okay it will be very easy to understand. ID in country where care check
country should be in India, USA, UK. Then only it will be inserted. Now, let's create this table. Run this.
The table will be created, guys. If I say select star from EMP2, what will happen? The empty table with
only columns will be coming. ID and country will be coming.
Now, Now, what I will do here is I will try to insert some records into this EMP2. Insert into EMP2 values
where ID is 1, country is Spain. Will this be accepted or not? Yes, it will be accepted because here
country can be India, USA, UK. Then only it will be allowed. Run this. Country got inserted. Select star
from EMP2. so one in Spain got displayed here. Another insert statement i am going to write. Insert into
emp2 values as two comma, two comma, some spain can i insert can i inside this it will not be inserted
because spain is another country which is not there in the list. Okay. Check condition list. Only these
three countries are accepted. If I try to insert some other country other than Spain, USA, UK, that will
not be accepted here.
Run this. You see check constant violated. Again, if i try to insert something which is valid, that is emp2
values as 2 comma usa okay if i try to do so, since usa is there in the India, USA and uk list of this
creation statement of the table, it will be accepted. So, run this properly. It got accepted. Select star
from EMP2. You see, one India, two USA. Apart from India, USA, UK, if you try to give another country,
that will not be accepted. So, like this, guys, we can use a check condition, okay? Check integrity
constant in the sql statements. So, this is all about the check integrity constant, guys. That's it, guys. See
you in the next video session. Thank you.
Bye.
So, in this video session, I am going to explain how to use default integrity constraint. So far, in the
previous videos, I have covered other integrity constraints like not none, unique, primary key, foreign
key, then check integrity constraint. All these five integrity constraints I already covered. as part of the
previous videos, the current video session i am going to cover the remaining and that means the last one
in the integrity constants that is default integrity constant so what is the purpose of using this default
integrity constraint? Default integrity constraint can be applied to a table column, okay?
When applied to the table column if if no value is inserted into that column. If no value is inserted into
that column which is specified with the default Integrity Constraint, then the given or specified default
value will be inserted. Let me explain with an example. Let's say there is a table. I will take a small
example. Let's say there is a two column table and I will first create the columns. Here, these are the two
columns. The first column name is ID and the second column name is experience. Like this. Now, if I
apply this default integrity constraint to this experience in such a way that default I will say some 5.
Some 5. I mean experience is 5. If you don't insert any experience,
If you don't insert, while inserting some records, let's say you are inserting some records here. You are
trying to insert some records. While inserting the records, you have provided the ID, but you have not
provided the experience. In that kind of cases, by default, 5 will be added. If you don't insert the value, it
will not be null, guys, because default value is specified for this experience as 5. So if you don't insert
something, it will become 5. If you insert something, whatever you inserted will come here. So this is
how guys default integrity constant will work.
So let me explain a practical mode so that you can understand these things in a better way. So there are
four databases here QFox, Succula, Sys and World.
I would like to use this QFox. How to use the QFox? I have to run this statement like use QFox. Then only
I can perform operations on the tables or create tables under the QFox. So run this. Now QFox has been
selected. DB has been selected. already there are few tables here. Let me delete them or drop them.
Drop two tables. So that things will be good for us. So there is no table under this qfos db now. Use qfos
Now create table emp1 table okay create table emp1 the id column first column is ID. Similar one. ID.
Which is of data type int. the second column is experience column. Name of the column is experience.
And its data type is again inch
and after this, okay, if i have to specify this default integrative constraint to this second column, that is
experience, then after the data type of this experience, I have to write default and say five. I'm just
giving a default value as five. So let me explain. When I run this, the table with these details will be
created. So if i say select star from EMP1, okay, if i say select star from EMP1, that particular table
having the columns id and experience will be displayed here. And this experience has been specified
with this default integrity constant and the default value is specified as 5. Now, if i try to insert some
records, insert into emp1 values, 1 comma. Here, I am trying to provide experience as 12. what will
happen?
This 192 will be inserted okay if you if i say select star from emp, you see 192 got inserted. If I Try to do
something like this. Insert into EMP1 values 2 comma 3. Experience is 3 here. Will it be inserted? Yes, it
will also be inserted. Select star from EMP for the employee having the ID as 2. His experience is 3. Now,
if I say insert into EMP1, here I am going to only insert ID value, not experience. values as experience, I
mean, ID is three. Only ID I have to insert i'm not i'm skipping the experience. I'm not providing anything
into the, inserting anything in the experience. Will this be inserted? Yes, it will be inserted. And under
the experience column, we are going to get the default value that is five guys,
okay? If you don't insert anything into the experience, by default, five will be added into that experience
column. Run this. It got inserted. If I say select star from EMP1, now you see, Third record, I only
inserted id as 3, but I didn't insert 5. Where did this 5 come from? Because while creating the table, we
mentioned for the experience column that if you don't insert anything into this experience column, then
the default value should be 5 like this. That's why 5 came here. So this is how, guys, default integrity
constraint works. I will give more examples now. Let me give more examples because here I explained
with int datatype. Okay, so other data type that is uh where care. Let's take another table create table
emp2 again id location location is where care.
Okay, where care or some 15. Okay, and here default value i am specifying as India. Let's say this is a
okay location. That's fine. Location as India. Okay, so i can give it as country also. Okay, so emp2 id int.
Country. Second column is country. First column is ID. Second column is country and which is of where
care, where we can enter the string type of text. So default value for that uh country type of data type is
India. Okay. So like this. Let's run this. So the record got inserted. If I say select star from EMP2, we'll get
an empty table only with the columns, column names, ID and country. There's no record under that.
Now I will try to insert some records.
Insert into EMP2 values 1 comma I am giving something as USA. So 1 comma USA when I insert it, this
record will be inserted because I am specifying the USA. So 1 USA will be displayed here. But if I try to
insert something like this. Insert into EMP2 only ID I will try to insert. I will not insert the other column
value. That is country column. I am not inserting the value. So, ID is 2, but i am not inserting the country.
Here, earlier usa is inserted, so usa is came. If I don't insert that insert the country using the insert
statement, what will happen? In place of that, India will be inserted. By default, values in Spain. If you
don't insert anything into this country column, so Spain will be inserted automatically.
So, if i say select star from emp2 you'll get to India. Okay? Like this. Next thing. Next thing is Uh, with the
date data type, okay? Date. Date kind of data type i'm going to demonstrate the same. Create table.
EMP3. ID int. Okay? And, uh, date of joining. Let's say there are some employees table like, that they
have date of joining, right? Date of joining. And, uh, the data type is date. And I'm going to give the
default value for this particular date of joining column. Like default. In the single course i have to give.
Let's say he joined on 2007. August. 15th okay like this this is a date in this format we have to give the
date guys if you have to okay so if you don't insert any date while inserting the records into the emp3
table okay into the date of joining if you are not inserting any dates by default this date will be added
inserted so it got created if i say select star from emp3 we will get an empty table having
no records that is id and date of joining now let's insert some records insert into emp3 values one id is
one and date i am giving some date guys uh 2015 okay and the month as 11 and the day as 22 some
random dates i am giving okay so if i am giving some date here in place of id one will be inserted in place
of date of column column date of joining column this date will be inserted both have the values. So,
default value will not be inserted. So, if i say select star from EMP3, whatever we inserted will come
here. But if i try to insert something like this, insert into into EMP3. Okay. Here, only id i'm trying to
insert.
i'm i'm going to skip the date of joining column okay i'm going to skip inserting the data into the date of
joining column. So, here if i say values and two only two i will give. Okay. So, brand this. this default date
will be inserted because you are not inserting any date here. So, select star from EMP3.
You see, 2007 default date. 2007, 8, 15th august 2007 got inserted here. So, this is how this is how guys
default default integrity constraint will work in sql statements. So, that's it, guys. See you in the next
video session. Thank you. Bye.
Part 75:auto_increment
Hello, everyone. Welcome to part 75. of SQL for beginner series. In this video session, I am going to
explain on how to use auto increment keyword.
So in this video session, I'm going to explain how to use auto increment keyword in SQL statements. So
what is the purpose of using this auto increment keyword? Auto increment keyword purpose is to
increase the value of the specified table column. Tables column. By one. Okay. If you specify this auto
increment keyword to a particular table column. Okay. When you insert some records, the table column
values will be incremented by one. But let me explain more. Okay. How actually it works. Let's say there
is a table. And it has a column. This has two columns. This is id column. This is like name column. Two
columns are there. Now, if you have inserted one record, let's say, you can insert some records like this.
Insert record one, record two. Like this, you can insert in future. That's fine. Now, before inserting any
records, let's say, while creating the table, you specified this ID column with auto increment keyword.
This ID column is specified with auto increment keyword. ID column is specified with auto increment
keyword. Now, if you try to insert some records into this table, Let's say you inserted here 5 and name
as Arun. Name is Arun. After that, as part of inserting second record into the same table, as part of
inserting the second record into the same table, you have only inserted name. That is Arun. But you
have skipped inserting the data into the ID column. In this kind of cases, because this particular ID
column is specified with auto increment.
So what it will do is, it will increment this previous value 5 by 1. 5 plus 1 is 6 so 6 will be automatically
inserted. Even though you don't insert any records data into the id column, which is specified in auto
increment the incremented value from the previous value will be automatically added here instead of
null values in general if you don't specify auto increment, what will happen? A null value will be inserted
in place of ID. But if you specify auto increment, automatically a incremented value from the previous
value will be inserted here for the table columns which are specified with auto increment, this will
happen. Now, one more rule is there. There is one more rule. Okay. In order to specify auto increment
keyword for this id column, this id column should already be specified with primary key.
Okay. If this id column is of primary key type, then only you can specify this auto increment. Okay. Then
only you can specify the auto increment keyword.
So let me practically like demonstrate all this stuff guys. Okay. So it will be very clear for us. Now, as you
can see, there are four databases. I am going to use this ClearFox database and try to create tables
under that. In order to use it, I have to use this statement like use ClearFox. Then only the database will
be selected. ClearFox database got selected. Now I am free to create, edit, modify tables from this. Now,
are there any existing tables? Yes, there are some existing tables. So what I'm going to do is to make
things clear, I'm just going to drop them.
I'm going to delete them. so that there is no table now under the qfox database. Now let me create a
new table. Create table, EMP1, ID, okay, ID, int data type. Second column is name, where care of 15
type, okay, where care of 15. Fine. Like this i can do that right now if i have to use now if i have to use uh
auto increment, let's say i would like to specify the auto increment with the ID. I'm directly specifying.
Let me show you what will happen. Here, if I have to specify this auto increment, the rule is this ID
column should be of primary key type, right? Should already be specified with the primary key integrity
concept. Then only you can specify auto increment here.
But the problem here is this ID is not specified with the primary key and you are directly assigning. What
will happen? You are going to get an error guys. Select this and run this. You are going to get this kind of
error. incorrect table definition. There can be only one auto column and it must be defined as a key.
Okay. That means if you specify primary key, then only the table will be created because this column
specified with auto increment will not work without primary key specified for that particular column.
Okay. That's the rule. Now run this. This time the table will be created because we have specified the
auto increment keyword to the table column which is already specified with primary key.
Okay. Now the table got created. Let's find it out whether the table got created or not. Select star from
EMP1. If I say select star from EMP1 and if we get that particular table in the results, that means the
table got created. The table got created without any records. It is an empty table. Now let's try to insert
some records. Insert into EMP1 values. I will insert something like ID as 5 and name as Arun. ID as 5 and
name as Arun I will insert. Now let's run this. When I run this, and select star from EMP1, you see the
first record 5, Arun got inserted. Okay? That's fine. Now I'll try to insert another record. Insert into
EMP1. This time, I'm not going to insert the ID value.
Only name value I'm trying to insert. EMP1 of name, values as only name I'm providing. I'm skipping the
ID. What will happen in this kind of situation where you're only entering the name and skipping the ID?
As I told you, since this particular ID column is specified with auto increment here, The previous value
will be incremented by 1. That is 5 plus 1. 6 will be automatically added. I am not adding any ID. But I am
only adding 1. But you are going to get the ID also. Incremented ID you are going to get. Select star from
EMP1. See that 6 came. I have not inserted anywhere 6. But previous value 5 plus 1 is 6. If you don't
insert, null will not be inserted in place of this.
Instead, the previous value plus incremented by 1 will be inserted. Now let's insert another record.
EMP1. Values. This time 9 comma Tarun. ok Now 9 comma Tarun will be inserted or not? Yes, it will be
inserted because here we are inserting it. ok Select star from EMP1. Run this. 9 comma Tarun got
inserted. That's fine. Now if I say insert into EMP1, this time again I am only providing the name. I am
skipping the ID. What happens? The earlier records id value will be incremented by 1. ok Here I am
giving Dinesh. Only name I am inserting. this time, the earlier record, uh, value is nine guys. Okay? nine
So, what's happening insert into uh here some mistakes spelling mistake insert into emp1 name values
as Dinesh.
Earlier record has ID. That nine plus one ten should be automatically added with the name Dinesh. Run
this. Select star from EMP1. You see? nine If nine is there, ten came. If five is there, six came. So, the
next value will be inserted, incremented by one if you are not inserting that. This is how the auto
increment keyword works. Now we have few more examples, few more cases. Let's further, let's create
another table. Create table EMP2, id, int, primary key, auto increment, same thing else, auto increment.
Only the table name is changing, remaining everything is same. Increment, comma, name, var char of
15. Like this I am trying to insert. Okay, I'm going to create a table. I'm going to create a table, EMP2
table.
Run this. It will be, EMP2 table will be created and it id column is specified with, again, auto increment,
which is our primary key type. That's fine. Same thing, okay, as a previous table. But I have to create it
again just for this demonstration. Now, if i say select star from EMP2, select star from EMP2, what will
happen run this so i am getting a table without any records. Okay. Without any empty table is coming
here. Now, if i say insert into EMP2. Okay. Insert into EMP2. The first record itself, I am trying to skip the
ID. What will happen? Earlier, earlier when i created EMP1, I try to insert the id and value. But this time,
the first record itself, I am not inserting anything.
Directly, name i am inserting. Like this. Values as Arun. Okay. So, what will the id will come or not?
Because earlier cases when i have no, when i have provided only name, in earlier cases when i provided
the name, the previous records value that is five got incremented by one and six got automatically
added. But here, the first record itself i am trying to add without the ID. So what will come here? Here,
one will be the first value guys. Okay? one will be automatically added. Okay? If this is your first record
and you are skipping the id which is specified with auto increment, then 1 will be coming. Okay. It will
start with 1. So, select star from EMP 2 and run this.
You will get 1.
Okay. Here, instead of 1, you will get null. I mean, instead of null, you will get 1. Okay. Fine. Now, again,
if you are inserting, what will happen? Name values this time 1. 2 will come. Okay. 2 will come. This
thing will continue. This thing will continue. So, if I say select star from EMP 2, one two is coming that's
fine now one more thing i don't want the first auto value auto increment value i don't want the first
auto uh auto uh increment value to be one i want it to be 100 how can i set that how can i set that while
creating the table only we have to do that okay create table emp2 id same thing primary key auto
increment same id is auto increment again comma name where care
you have to complete this, okay? Where care 15, okay? This state, create table table name with all the
columns. After this, you have to write again at auto underscore increment is equal to 100, you have to
say. Earlier, here, by default, one got inserted if the first record is skipping the ID, one came right one
came here but here if you don't insert the first record id for id column, okay? While inserting the first
record, if you don't specify the ID column value, then the default value is going to be 100. It will start
from 100 here, started from 1. Now we are going to see the starting from 100 because auto increment
first value set to 100. So you have to run this statement.
Let me run this. The table, there's some mistake here. Create table, EMP3 I have to set, the same table I
have. Here, EMP2 is already there. I am trying to create the same table. Now, EMP3, I have to create.
Run this. The table got created. Now, select. Just to confirm the table got created, select star from
EMP3, I will say. mp3 Run this. Empty table with id and name column got displayed. Now, insert into
EMP3. Okay. Insert into EMP3. I am skipping the id value. I am only providing the name. I am skipping
the ID. Name is Arun. I am giving. In this case, the first record will be inserted. Since I am not providing
ID and the default first value of that particular record should be 100.
It should start from 100. So, run this and now say select star from EMP3. It will start from 100 guys.
Earlier case, it was starting from 1 automatically. Now, auto increment value is starting from 100 this
time. Now, if I say insert into EMP3 name values as, again, another name, Varun, okay? Now this will
insert 101, okay? This time 101 will be automatically added. 100 plus 1, 101, Varun will come like this
guys
this how we have to use auto increment keyword in sql statements. I explained all the different cases for
you. So that's it, guys. See you in the next video session. Thank you. Bye.
Hello, everyone. Welcome to part 76 of SQL for beginner series. In this video session, I am going to
explain on how to use insert into SQL statements.
So in this video session, I am going to explain how to use insert into SQL statement. So what is the
purpose of using this insert into SQL statement? the purpose is to copy the records from one table to
another table. Another table. Copy the records from one table to another table is the purpose of this
insert into statement. Let's say there are two tables table one table two in table one there are some
records. Okay? In table one there are some records which are already there. Now, from this table one i
would like to copy all these records into another table. Okay? Into a other table. I would like to copy the
records. So how to perform this copy operation from one table to another table of the records?
Here asterisk is there. Asterisk symbol means from all the columns, records from all the columns of the
city table got displayed here. Now, I would like to know what this ID column and its data type. This ID
column has some data type. This name column has some data type. Country has some data type. District
population has some data type. So what I have to do is, now we have the city table. Now, this is a city
table. From city table, I want to copy the data from city table to another table. This table, I am going to
create this. I want to create this new table. New table, I would like to create. I would like to name this as
new city. New city table, I would like to create.
It's not there in the DB. Under the world DB, that new city table is not there. I want to create that. But if
I have to create, what is the intention of creation? I would like to copy these records into this table. this
records from this table to the city table to the new city table. That means i should have the same type of
columns in the new table also. In the new city table also if this id column is there in the city table. Then
here, in the new city table also, I should have the id column. Then only i can copy. I mean, ID type of
column. The name can be different, but uh i will show i will show you how things can be possible.
Okay? I'm going to In order to create that new table, I have to find out the data types of these different
columns of the original table city from which I want to copy the records from. So, for that I have a
command like describe city which will give the details of this all the columns of the city table with the
data types. Run this. All the columns, ID column is there in the city, name column, country code,
population, everything is there and they have the data types. ID is of int like that. So, now I am going to
create another table. Create table. I am saying new city. New city. So here, NID. Instead of ID I am just
giving NID you can even give ID also.
I am just intentionally providing NID NID and data type should be here. Cities ID column has a data type
as int. Here NID should also have the int. Then we have name. ok Name. so Here name I'm giving only
one column. I'm just changing the name from ID to NID. Okay. Here name is care of 35. I'm giving the
same data type just to make sure that things are working fine. Then we have country code. Country
code. Country code is care of the comma. We have district. District is like care of 20. Then we have
population. population is of int. Okay? In data type. So, like this, some records are there in the new table
also. I mean, some columns are there in the new table also.
New city has the columns. The column names can be different, guys. In city, the column name is id. But
in the new city, the column name is different. But remaining columns are same. That's fine. It can be
same. It can be different. That's okay. But data type should be same. Okay? We have to specify the
different similar data type because you are going to copy the records from city table to new city table.
That's the reason we have to make sure that data types are same. But names, column names can be
different. Not a problem. Okay, run this. The table got created. Now in this table, let's check any records
are there. Select star from new city. No records will be there guys it is an empty table.
Okay. Before I copy, there are no records in this new table, new city table. Now, once this process is
done i am going to use insert into statement. Okay. This insert into statement i am going to use. to copy
the records from city table to new city table which doesn't have any records.
This city table has lot of records.
Those records I am going to copy into the new city table. How to do that? Insert into which table I have
to insert? New city table that I created just now. Insert into new city. I have to say select what records I
have to copy from the city table. Those records I have to specify. Select star from city I have to say. So I
am going to copy all the records from all the columns of the city table into the new city table.
This is the statement guys. Insert into new table. Which records have to insert? All the records from all
the columns of the city table I am going to insert into the new city. Okay. Run this statement. Now
inserting into. It's running. So how many records affected? There are 4079 records in the city table which
got copied from the city table into the new city table guys. Okay. Now, if I say select star from new city,
you will see all the records. All the records will be displayed. Here, how many records are there? 1000,
2000, 3000, 4000 and next set. 4079 is the last
. So, this many records got copied from the original city table to the newly created new city table. This is
how we can do.
And similarly, what I am going to do is, I am going to create another table. This is one case study where I
explained how to copy the all the records from all the columns of the city table into the new city table.
Now, what I'm going to do is I'm going to create select star from city is already there. Okay. So, I'm going
to create another table. Okay. Another new table. So, similar to new city, I'm going to create another
table. Let's say I'll give some different name guys. So, n2, nt city. Okay. New second. T stands for 2, let's
say. Or CT2. I will say CT2 better. This is more readable. So, second type of CT table I am going to create.
So, for creating I have to describe the original CT table which all the columns and data types will be
visible. So, I am going to create another table just for demonstrating other stuff. Create table CT2.
And here I am not going to provide all the columns. I am going to only specify id column. I mean, I can
say TID, int, okay? Column can be same or different, that's fine. I can say id also not a problem. Then
name of the city. It's a care of 35. Then country code, okay? Three things. Only three columns i am trying
to create. Here, original city table has how many columns? One, two, three I mean, sorry, 1, 2, 3, 4, 5. 5
columns are there. ID, name, country code, district population.
These are the 5 columns that are there in the original city table. But in the new city table, I am going to
only provide 3 columns. Okay? Not all columns. Only 3 columns. Care of 3. Like this. Okay? Only 3
columns I am trying to create inside this city2 table. So, in this kind of situation, if I have to copy from
the original city table, having the 5 columns to the new city2 table, which is having only three columns.
Is it possible? Yes, guys, it is possible.
We have to tweak the insert into statement a bit. That is, I have to say insert into new city name is city2,
right? New table is city2. Into the city2, I am going to copy the records from the city table.
But here, into the city2 table, I am going to only copy the records into two columns, that is, ID and
name. Not more than that. Even country code also i am not selecting. Into the new city, I am copying the
records from city table into only two columns out of three columns available. ID, comma, name. Okay?
Now, here i am going to say select. Select ID from the city column. I am city table. ID, comma, name
from the city table. Okay? So, only these two columns i am going to select. From which table? City table.
like this i have to say. Here CT2 table has three columns. CT has five columns. But I am going to copy the
records from ct table into ct2 table only into the two columns.
Even though ct2 table has three columns, I am trying to copy the column. Here you can see that. I am
going to explain here more clearly. Here five columns are there, right? Original table ct has five columns.
c2 table has how many columns? three columns. But what i am going trying to do? I am going to copy
only two columns. This is what is happening. Right? From the five columns, I am going to copy records
from two columns. So, the CT2 table has three columns, but only two columns I am copying. This is
possible, guys. Here, five columns are there. Here, three columns are there. I am copying only two
columns. This is possible. That's what I am trying to do. Okay? Insert into CT2.
Only copy ID and name record data from the CT table into the CT2 table. Okay? Like that. So, what will
happen for the country code that is there in the city 2 it nothing will be there. Null values will be there,
guys. Okay? Null values will be there. Only data will be inserted into id and name. And country code will
have the null values. So, here whatever the columns i selected, those columns have to select from the
city table.
Copy from the city table so id comma name so id comma name same is there. Okay? Now, run this.
Running. Some 4079 rows got Inserted. Okay. Select star from CT2. Just take the ct2 table. Now, you run
this. Three columns are there in CT2.
But data is copied to how many columns? Only two columns. And into the remaining column that is
country code of the ct2 table, all the null values got. Okay. There are null values because you have not
inserted anything from the you have not copied country code from the ct table. Only you selected to
copy two columns from the ct table. to the city2 table. Okay? This is how it happens guys. Fine. So, and
also we can use where class. Okay? While copying we can use where class. Let's say i will create another
table, similar table. Okay? Same thing i am copy pasting here as you can see. Here city3 let's say. Okay?
And same columns. That's fine. Now, I will create this table.
Empty table will be created. Now select star from city 3. No records will be there in the city 3 before I
copy. You see empty table is there. Now what I am going to do is select star from city. Okay. Here I will
say I will put a where class condition. Okay. So district should be something. Okay. So our country code.
Maybe we can do the country code. Right. Out of all these countries only one type of country. AFG
country code. Okay. Where country code is equal to something that I want to add. So here I would like
to copy the records from the city table to the city2 table. Okay. Similar way. But here only two columns I
am going to copy.
Even though five columns are there in the city, I am going to copy two columns into the city2 table
which is having three columns. Okay. And here where country is equal to what is that code? AFG. I am
going to apply. Okay. So same thing. Earlier whatever I explained, the same thing for city2. the same
thing but here we are going to have an extra condition where class condition is going to be there. So
how to do that? So I have to say insert into okay insert into which table city three table okay insert into
city three only to id and name column okay only into the id and name column. So here i created the
table or not? Let me see. i already created,
I guess. Yes. Select star from cd3 no records are there. Now insert into cd3 okay id comma name. Then
select id comma name from original table. That is city table. Okay. City table. Where? Where? Not all
records i want to copy from this uh city table into cd3 i would like to only copy the records whose
country code. is equal to, okay? What is that country code, guys? AFG. AFG should be the country code.
Like this. If I do so, not 4079 records will not be copied, okay? Less number of records will be copied.
Let's see that. So, only four rows affected. Only four records came, okay? If I say select star from ct2
okay here we have not like uh okay So, how many records actually?
So, 1000 rows. Sorry. This one guys. Okay. So, 1000 got returned.
Something is happening. Okay. So, whatever all these records which are from the country code AFG got
copied. Not all records this time. Only the records from the country code AFG got copied into the CD3.
This is how guys we can use. This is how we can use the insert into statement. in SQL. Okay. If you have
to use insert into statement, we can use like this. The purpose of the insert into statement as explained
is to copy the records from the one table to another table. Okay. Either we can copy all the records from
all the columns of one table to another table or we have the flexibility of choosing the different columns
from which we need to copy into the new table.
Okay. So guys, this is all about the insert into statement. So that's it guys. See you in the next video
session. Thank you. Bye.
Part 77: AS Keyword
Hello everyone. Welcome to part 77 of SQL for Beginners series. In this video session, I am going to
explain on how to use AS keyword in SQL statements. So, in this video session, I am going to explain how
to use AS keyword in SQL statements.
What is the purpose of using this AS keyword in SQL statements? What is the purpose? The purpose of
this keyword is to create a new table. Okay? The purpose is to create a new table with the records of an
existing table. To create a new table with the records of an existing table, we have to use as keyword.
So let me give an example. Let's say there is a table here. Okay? Let's say there is a table. The table
name is like something like uh place okay table name is place. and in this place table there are some
existing records like this some records are there some records are available with the proper data now i
want to create another table let's say new place table with the same table records and columns and
everything okay i would like to copy this table into a new table this new place table is not created yet i
am going to create right away here using the as keyword i can do that okay i can create with the same
records i can create a duplicate copy of this table with a new name okay new table name i can create the
duplicate copy of this place table so all these records all these columns of this particular table with a
different name new place will be created here this is possible with the help of this as keyword okay if
you use this as keyword while creating the table then we can create a copy of the existing table with the
same records
Fine.
So let me practically demonstrate how to use as keyword in SQL statements for creating a new table
with the records of an existing table. Fine. So here, as you can see, there are a few databases. These
three databases, circular assist and world databases came by default when I have installed and
configured MySQL in my machine and other database QFox has been created by me, has been created
by me. So, now I would like to work on this world database. For that, I have to select this database called
world. So, use world I have to use. Then, current selection is Firefox. Now, I would like to select world.
So, select this and run this. The world database got selected. Under this world database, since I have
selected this world database, I can perform any operations on any of these tables of this world
database.
Now, as you can see, there are some default tables available here. CTE, And city, country, country
language, place. Okay. All these are the default tables. Now there are some, I have created some, I have
performed some operations guys. I'm just dropping those tables. Okay. In the previous videos or
whatever it is, I have worked on some, these tables are created by me guys. Whatever the tables I'm
deleting from here are created by me. I'm just dropping them because I don't want them to have. So
drop. So by default, when you have this whole database, coming from this mysql right by default they
will have four tables under the whole database you will see city country country language and place
tables okay so now i would like to work on this place table okay i would like to create a copy of this place
table in there by creating a new table you will see that in action so the place table is already there so i
would like to find out what are there in that place table select star from place i have to say if i say that all
the records from all the columns of this place table will be displayed here run this
you see, all the records of this place table from all the columns were displayed here.
Now, I would like to create a new table. Okay, new table. But that table should have should be the copy
of this existing place table. Okay, I'm going to create a new table in this world database. And that table
will is going to have the same details, same record same columns of this place table. So how to do that
create table okay create table what is the table i would like to create? new place okay new place table
new place old old play uh normal i mean available existing uh table is place table now i am going to
create a new table with the name new place.
As, okay? Create table new place yes as select star from place, I have to say. Okay? This is a single
statement. Create table new place as keyword how to create this new table? As this table, that is place
table, all the column, all the records from all the columns of the place table should be copied into the
new place table while creating the new place. If I run this, okay, before, before creating the table, if i say
select star from new place, the table itself is not there. We'll get an error. Okay. We'll get an error saying
that table doesn't exist.
This new place table is a, is going to be created. It's not there in the world database. after running this
create table new place as select star from place, run this.
Now it's creating the table and at same time it's copying all the records columns of the place table. So
now if i say select star from new place this time, you see whatever that was there in the place table that
is now there in the new place table all the columns all the records fine there is one more thing okay this
this is how we can use as keyword for while creating the table for copying all the records, all the
columns of the existing tables. Fine. Now, the next case i would like to explain is, I would like to create
another table. Okay. I would like to create another table. Let's say, create table place two okay place
two table i would like to create.
As, this time, I don't want to, I don't want to copy all the columns of, okay, all the columns of the place
table i don't want to have here place table has three columns, ID, name, district. When I created the
new place, I also got the ID, name, district into the new place. But here place two, but while creating the
place two, I don't want this three columns. I only want this name and district to be copied from the
original place table. How to do that? Create table place to as, select. If I say asterisk here, this will copy
all the columns, okay? All the records from all the columns will be copied from the place table. But here,
instead of this, I'm going to specify name, district from place table.
From the original place table, I'm only going to copy, while creating this place2 table, I'm going to copy
only the name and district columns and their data from the place table. Run this. Before running this,
again, same thing. Let's follow same thing. Select star from place2 table. The place2 table I'm going to
create, right? select star from place to this table doesn't exist because you have not created it. Now if i
run this, create table place to as select name comma district from place, only these two column should
be copied, okay? Not everything. So it has been executed. If I can run the select star from place to you
see the new table has been created only with two columns, name and district, but all the records came
with the data of name and district columns only from the place table to the place to
table that is newly created table so guys this is how we have to use as keyword in SQL statements for
creating the tables by copying the existing records and columns from the existing table so that's it guys
see you in the next video session thank you bye
hello everyone welcome to part 78 of SQL for beginner series. In this video session, I am going to explain
on how to use if null function so in this video session i am going to explain how to use if null function in
sql statements.
So let me practically demonstrate this if null function for you. Here, let's say there are four dbs and uh
these are like default game dbs with MySQL. That is circular assist and world game by default with mysql
whereas qi fox is one db which i have created in one of the previous videos.
i am going to use the myself created db that is QFox. How to select that? You have to say use QFox,
okay? When I say use QFox, this particular db will be selected and i will be able to create, update, modify
or do operations on the tables which are there under this qfox database. And before doing any
operations uh there seems like there are some tables available, existing tables. I'll right click on them
and simply drop them, okay? I don't want to have any tables now to make sure like everything is fine.
Fine. Now, I'm going to create a table, guys. Now, I'm going to demonstrate, practically demonstrate
how to use if null and where we have to use the sql statements let's say let's say i would like to create a
table like create table emt1 id as in and salary also it Okay, I'm just creating a table like this.
Create table emt1 with two columns. I'm creating a table having two columns like this so first column
column is id okay column name is id and second column name is salary okay and both are into data
types into type of data here also into type of data and in this i am going to insert some records like this
some three records i am going to insert guys first record let's say id is one second record id is two third
record id is three for the first record having the ID as 1, I'm giving the salary as some 14 lakhs. And for
the second record, having the ID as 2, I'm giving the 7 lakhs. And for the third record, having the ID as 3,
I'm not giving anything.
I'm just inserting null. That means I'm not inserting anything. That means if you are not inserting, null
will be inserted. Now, in this kind of situation, now the table got, table, I have to create the table first,
right? I am in this direction. I have to fill the data like this into this table after creating.
So let me first create the table create table emp1 run this the table will be created. And insert into, if i
say insert into emp1 values as 1 comma salary as some 14 lakhs. Okay? Fine. Insert it. The data will be
inserted. This first record 1 14 lakhs will be inserted. Now, second record. Insert into emp1 values as 2
comma some 7 lakhs. This value also, this record will also be inserted.
Run this. Now, third record. Insert into emp1 values, but here i am trying to only insert the id value okay
id column value, but not the salary. That is only the id number 3 i am inserting but without the salary so
this also i am trying to insert run this so three records will be inserted if i say select star from emp1 okay
if i say select star from emp1 what will be the result what will be the result the table will be displayed
guys that is id salary id as one two three and salary as uh 14 lakhs seven lakhs and third since you have
not inserted any salary into the third record We got null inserted here. Okay. Null automatically inserted
there.
Now, in this kind of situation, if I have to write a select statement like this. Okay. Now, I am going to
explain the purpose of using this if null function in the SQL statements. Okay. If I say select. Okay. If I say
select salary plus 1 lakh. This kind of operation I am trying to perform. Salary plus 1 lakh from EMP1.
What will happen? if I say, if I say select star from EMP1, this null value will be displayed. That's fine. If I,
in other select statement, if I say select, the circular brackets, if I say salary, this salary of the employee,
okay, from EMP1, if I say, what will happen? If I run this, null is coming here. I am trying to add one like
but that one like is not getting added to the null.
Null plus one like is null, it's happening. But instead, I want something like, If I add the 1 lakh to the
salary which is not there, then it should be coming as 1 lakh.
If I want such kind of result, what I have to do? Here, for the first record, we have inserted 14 lakhs. So,
14 lakhs plus 1 lakh, 15 lakhs. So, it got displayed properly. For the second record, 7 lakhs. 7 lakhs plus 1
lakh, 8 lakhs. That also got displayed properly. This select statement is working fine for these two things.
But third record, we have the null value. We have not inserted any salary. So, null plus one like it's
displaying as null, guys. Instead, I want one like okay here if if no value is there, I want to get one like
Okay?
In the results. Instead of, here 15 likes is fine, 8 likes is fine, but i don't want null here in the result.
Instead, I want one like in the results. What I have to do? For that, we can use if null. Okay? If null, we
can modify that. So, select. Okay? Select if null of salary okay select if nil of salary comma zero. Okay.
Here you have to provide a bracket and again say plus one lakh. What will happen from EMP1? So let me
explain this. What is going to happen here? So here instead of giving the normal salary column, I am
surrounding the salary column with a if null function if the salary is null, then assume that is zero. I'm
just saying that if the salary is null, assume that that is zero guys.
Zero plus one like will happen. Then you will get one like here. Let's run this. Run this. You see this time
15 likes eight likes and one like you got. Because salary is for the third record has been treated as not
null. It has been treated as zero. Okay. If null is there, we asked for the sql statement to consider it as
zero. So zero plus one like is one like has been displayed here. If null is there, If you want to consider it
as 100, what will be the result? Let us see. Sorry, I did not execute. You see, 1 lakh 100 is coming here.
That means 100 plus 1 lakh. If null is there, consider this value like that. You can use for such kind of
situations where you want to work with this kind of queries.
Select queries. Even though the record value is null, still you want to perform operations on that
particular record. Then you can use if null and then modify the value to get your desired results. Okay,
this is how we have to use if null function in SQL statements. So that's it guys. See you in the next video
session. Thank you. Bye.
Hello everyone. Welcome to part 79 of SQL for beginner series. In this video session, I am going to
explain on how to use the different keywords like case, keyword, then keyword, then keyword and end
keyword. So in this video session, I am going to cover four keywords. That is case keyword. Case is a
keyword. Then we have when keyword, then keyword and end keyword.
So these are the four different keywords that we can use in the SQL statements. And if we have to use
any of these keywords, we have to use all these four keywords together. Together we have to use four
keywords to solve something. So what is the purpose? of using this four keywords in sql statements.
Suppose if you want to write something into the sql statements like this. Okay. Case. You want to write
something like this into the sql statements. Different sections of the sql statement we can write this.
Case. When. Here case is a keyword. Okay. Case is a keyword i'll underline it. Here when is also a
keyword. When. some condition you have to give. Okay. Here I have to specify some condition.
Let's say a condition is like experience is greater than 5. is a condition. When condition then result. This
should be displayed in the result. Okay. If this condition is satisfied, you have to display something in the
result. Then you have to say the experience is greater than 5. Now again when when experience another
another when then I am writing okay here when is a keyword and then is a keyword I am constructing
using case, when, then keywords, okay? This kind of things we are going to implement in the SQL
statements, okay? First, understand how to use case, when, then. Then you can understand how to use
this structure in the SQL statements, okay? So, when equal to 5 then we have to write
The experience is equal to 5. This particular text will be displayed in the results. Again, one more
condition. That is one more kind of line here. That is when experience is less than 5, then the experience
is less than 5. and finally, you will say end. Okay? So here, how many keywords are there? Four type of
keywords are there. Case keyword, end keyword, when keyword, and then keyword. Okay? These are
the four type of keywords. If we have to create this kind of statements, okay? If we have to use this kind
of things in the sql statements, then we have to use four keywords like case, when, then, end. Okay?
These are the four keywords we have to use in the sql statements.
Now, we can apply this for a We can use this in a SELECT statement. Where we have to use? We have to
use this kind of keywords in the SELECT statement. For example, we have something like this. SELECT ID
NAME ID NAME comma Then you can start here. CASE All these details you can provide here. all these
four details, case, same thing you can provide here. In the select statement, you can provide us okay?
So, okay. Control C, Control V, Control Z, Control Z. Yeah, Control b Here, case, case will start like this
and it will end. After that, you will say from from emp employees table, okay? Like this. select ID, name,
comma, case. Okay? This is a third column that i am going to display in the results.
Like this. Let me practically demonstrate, guys. Okay? Now you know the structure of how to use case
and when then right i am going to implement this in one of the sql statements. If I explain practically,
you will understand more about this. Okay? How to use and all. Otherwise, you will get confused. So,
here, in one of the sql statement like select star from employees, in between somewhere, we have used
this kind of structure. Okay? In the select statements, different uh Uh, in different sections of the select
statement, we can use this case to end along with this when, then kind of things. Let me explain
practically so that you can understand more guys. So for this, what i'm going to do is i'm going to open
uh this w3 schools sql try okay just google search for w3 schools sql try you'll get this link where you can
practice your sql statements now here databases are also displayed.
Let's say i would like to work on. First, I would like to work on. this products, okay? Products. Select,
select, star from products, I will say, okay? There is a table known as products table in this page, okay?
So, if i say select start from products and run this, what will happen? All the records from all the columns
of the products table will be displayed here, like this. So, in this products table, there is a section like
price. As you can see, there are different prices here, right? For each and every product. Here choice has
18. Here Chang has 19 price. Okay. Like the different products have different prices here. So I'm going to
use a select statement. I'm going to write a select statement where I'm going to implement this case and
when then keywords.
Okay. So we just see that how I'm going to do that. Select. I would like to say select product name. Okay.
If I say select product name from products table, what will happen? Only products. Only products name.
product names will be displayed. Only this column with all the details under that will be displayed. If I
say again comma, okay, I'll make it down, okay? So like this. Select product name, comma. Few other
details i would like to display. Product name, comma. Here price i will display, okay? Price. Again
comma. And I would like to display one more column also, okay? Product name, price. But I customized
the kind of column i would like to display with some by implementing this, case end okay when i end
then so let's see here what i'm going to do.
Third column is case. Okay? Case. This is the first column. First column is product name. Second column
is price. Third column is case. Okay? Case. Here, just to make you, make sure that you are you can
understand this, I am writing in the next line guys okay you can write here also. Like this you can write. is
when. Okay? You can continuously write. but it will not look good, right? I have to move it, I have to
break into multiple lines so that you can understand what's going on. If I write a case, so this is the first
column, second column, this section is going to the third column, okay? That you'll understand soon.
When price is less than 10, okay? When price is less than 10, then display the price is less than 10.
In the third column, as part of the third column, here first column product names will be displayed. In
the second column, while displaying, the prices will be displayed. In third column while displaying, it will
display, if the price is less than 10, it will display that the price is less than 10 text in the third column.
Like when price is equal to 10, then the price is equal to 10. I am trying to display in the column. When
price is greater than 10, Then the price is greater than 10. I am trying to display. Okay. So here I have
used so far three keywords. Case, when, then. Okay. When, then. When, then. When we will have a
condition, then we will have the result.
Okay. When this condition is satisfied, then this result should be displayed. When this condition is
satisfied, then this result should be displayed in the column. When this condition is satisfied, then this
result should be displayed in the column like this. So, once you are done with the case, right, you have to
end it. Okay. For that, we have to use end keyword. Case, when, then, end. Four keywords have been
satisfied. Now, again, you can say comma and another column also you can display. That is, I would like
to display unit. After this third column, I would like to display unit column. Okay. Here also you can
mention, not a problem. End, comma, unit. Okay. This is third, up to here is the third column.
This is the first column, guys. Comma, second column. Comma, third column. Comma, fourth column.
from products. If I run this, what's happening? First column is product name. Okay? Product name. First
column. All the product details from the product name column got displayed here. Then, I said price.
Second column i mentioned it as price. So, all the prices from the prices price column got displayed here.
Okay? Fine. For all the 77 records. Here, products table has 77. Total 77 records came. Third column is
from here to here, guys. From case to end. Okay. This is the third column. Case end. Third column is
starting here at the time of case and ending at the end. And in between some conditions are there. If the
price is 18, it is greater than 10, right?
So the price is greater than 10 will be displayed here in the third column. You see this is the third
column. Okay. The price is greater than 10 got displayed. For this also the price is greater than 10
because it is 19. 10 means the price is equal to 10. Okay. second condition, the price is equal to 10.
Okay. Price is equal to 10. Then you have to display the price is equal. That got displayed here. So for
each and every price, the associate text is displayed here. Okay. The price is greater than 10. The price is
less than 10. The price is equal to 10. Like the different type of text is displayed in the third column. And
fourth column is unit.
Under unit, all the unit uh column details got displayed here. That's fine. Now, this doesn't look good
guys. Okay. This name doesn't look good. Column name doesn't look good. whatever we have written
the sql code, right? SQL kind of code. That code, code kind of syntax code displayed here. Okay? So,
instead of that, what i will say is after end, I will say as. You remember as right as keyword how to use as
keyword? Okay? If you want to provide an alias name, okay? For this column, since this particular
column doesn't have any column name here and it's displaying as it is here, I will say price details. As
price details. If I say something like this and run this this time a proper column name, like whatever you
provided here after as, is alias name, guys,
okay?
Price details is the alias name of this particular thing, case and when, okay? Under price details, for each
and every price, what is the price that got displayed? So this is how, guys, inside the sql statements, like
select sql statements, we can provide case n okay? In as one of the column for returning the details from
the table. Fine, this is for displaying the result. Now, the next way we can use this case end, okay? That's
the first example, guys. The second example is in the where class. I will be using in the where class. For
that I am going to take the customers table guys. Select star from customers. Run this. So all the records
from all the columns of the customers table will be displayed here.
Total 91 records as a total 91 records theme. Now here I would like to add a where class condition.
Where some condition I would like to add. Where cd. is equal to. Okay. I would like to retrieve all the
details of the customers who are from the city. Okay. For city, I would like to provide a condition. I
mean, for the city condition. After where class have to provide this condition. City is equal to some city i
have to provide here. If I provide something like Germany, what will happen? All the customers who are
from Germany. Sorry, this is country, right? So, Berlin. Let's say if i provide Berlin. Okay. What will
happen? All the customers who are from the berlin city will be displayed.
Okay. only one record is there in the table. That's fine. So, like this we can filter the records. But if here, I
don't want to write this value. Instead of that value, I have to provide case. Okay? Just to make sure that
you understand it well, I have to provide city here. Okay? Inside this circular brackets, I'm providing a
kind of case kind of condition for that i will just move it down so that you can understand what's
happening there. Case when okay case when country okay condition after when i have to write the
condition. Country is in. In operator you know right. In one of the previous videos i explained. In. The
country is either usa or UK. Okay. Then. Then give the city of these countries.
So you have to assign the city of this usa you get to this city. Okay. That's fine. Otherwise when. country
is not in. Not in. Opposite of. Okay. If it is, if the retrieved country from here in one of these records is
not in the USA or UK. Okay. I have to write like that. So some condition I am trying to create guys. So
that the main purpose of this example is to show you that in where class condition also we can use this
kind of case end. Okay. That is the reason I am showing here. UK. Then if the country is not in. USA or
UK, then give something as Berlin directly. The city should be Berlin. If the country is in USA, UK, the
cities of this USA, UK are accepted.
Those will be assigned. All the records of the countries USA, UK, customer records from USA, UK having
any city will be displayed here. That's fine up to here. But if any record is retrieved for that the country is
not in USA, UK, then it will it will only assign the city as Berlin. Okay? That's how it will work. The
condition is something like this. After this, let's say we are done with the statements then what which
keyword i have to use here? I have to use end keyword okay this end so like this. Like this, you have to
we have to write so you can write like this. You can remove this if you want. So, that it will look good.
Select star from customers where city is equal to this kind of this kind of case case case keyword then
keyword, then keyword.
based on this, the city will be assigned to the city and based on that records will be retrieved. from this,
you will get some results. We can analyze the results and understand it back again okay so select star
from the select all records from customers who are from the city. If the country is USA, UK, here you see
uk uk uk uk usa you say all the countries are accepted. Okay. All the countries from the USA, UK are
accepted here. Okay. All the cities, all the customers who are from different cities of USA, UK are
accepted here. That's why we are getting all the records of UK, USA country having different cities here.
London is from UK. Uh, some lg is from USA.
Again from uk course is there. Okay. Like many countries are there. Okay. UK, USA. Uh, cities from
different countries are coming okay two countries you will say uk countries different city records from
customer records from different cities of UK, USA are coming here because of this line. But when the
country is not in USA, UK, what if the country is not USA, okay then only get the records from the berlin
city, okay? If the country is USA, UK, then get the records from any city which is there in the USA, UK
countries. But if the country is not usa or UK, in that case, only get the records from the Berlin. Only one
record is there in from berlin city, guys, okay? Berlin country is germany and this only single record came
and all the remaining records are from USA, UK having different cities, okay?
From different cities, different customers came from USA, okay Outside USA, UK, only the customers
came from berlin City. Okay. So like this we can write guys. Okay. Here also we have used case, when,
and keywords. Okay. When, then keywords. So one more case case one more example i would like to
give. Third example where we can use uh another example guys okay for uh using the case, when, then,
and keywords. Okay. The SQL statements. So here i will select star from customers table. okay from
customers table order by if i say city what will happen guys select start from customers order by city if i
say what will happen all the all the customer records from the customers table will be retrieved
according to the ascending order of the city.
Right? By default, this is ASC. If I don't specify asc here, if i don't specify asc here, by default, order by
will have this asc specified. This is a default of default order okay if i have to do in descending order, I
have to provide ESC, okay? This is not by default. If you don't provide it will become ascending. Like that,
okay? Either you can provide asc keyword or you can ignore it. By default, order by will order the
records in ascending order. Select start from customers, order by city. If I say, what will happen? All the
91 records of these customers will be displayed here according to the ascending order of the city. Let's
see. Run this. Total 91 records are getting displayed here according to the ascending order of the city.
First A came, then B, C, like that, okay? So, ascending order. Here you see all these IDs and everything
other became random, okay? 17, 65, 55, 29 because these are in ascending order. So, based on this
ascending order, this customer ID will be in random only, okay? Fine. Now, here I would like to provide
this case when, then, end, okay? Instead of directly giving a particular city, I will provide a kind of thing
here, okay? So, here I have to provide Case. I will move into next line, next line so that it will be easy to
understand. Case. When. When condition i have to give. Okay. When country, same condition i will take
which have given in the previous uh example also. Country in.
USA. UK. Okay. Then. then what? Then say country. Order by country. Okay? If the country, if the
retrieved customer records from are from the USA, UK, then order those records according to the
country. Okay? So USA, UK countries will be ordered according to the country names. Whereas
ascending order, they will be ordered by default anyhow. Okay? When country is not in usa or UK, Then,
order the records, order this customer records according to the city. If the country is in USA, UK, order
those customer records which are retrieved using the country. If the country is not there in USA, UK,
then order all the records of the countries which are not USA, UK records in in terms of city. Okay, I can
write something like this.
If I run this, okay, there is a mistake here because i have to end it, right? I have to use the end keyword.
Okay, I didn't write. Case, when, country, like this i have tried case when country in, then country. When
country not in, then order by city order by country order by city here order by some column should be
there. That column is either country or city based on this condition. If the condition is where the
customer is from USA, UK, then the uh that particular record will be ordered according to the country.
Whereas, if the customer record is retrieved from the uh country which is not in USA, UK, then the
ordering of the such records of the customers will be done by the their city name okay like that
i'm trying to do run this so here you see here not all the things are ordered by either only city okay it's
ordered by both country and city first let's see the country are these in any order countries are not in
any order g is coming first then s b i they are in random order s is coming here again g is coming okay
there's some random order but if you go to this countries like usa uk you can see that there is some
order okay you first uk came all the records of the uk came.
After completing all the records of UK, then only us came usa came okay that why it's coming coming
like that countries these two countries are ordered in ascending order okay remaining countries will not
be ordered in ascending order.
Only this USA, UK will be ordered because you see, U is common from uk and USA, but K, first k is
coming, then s will be coming right ijkl mnupic urs okay so s is uh this is in proper ascending order. That's
fine. Then, For remaining countries other than the USA, UK, all the other countries, all those records
should be ordered by the city. So, you can see the cities for remaining countries. Here, A is there, B is
there, B is there. Like this, C. After C, we got F. F, G, H, I, J, K, L, M. Then, we got N, O, P, R, S, T. But you
see these are not ordered in ascending order. After T, L came. Because for UK and UK is exception.
If the country is UK or USA, it has to be ordered by country. Otherwise, for all the other cities of the
countries, they will be ordered in ascending order. Based on the city, they will be ordered in ascending
order for the remaining countries. For only this USA, based on the country, they will be ordered in
ascending. But for other remaining records, based on the city, they will be ordered. So like this, guys, we
can provide multiple conditions using the case when, then, and we can achieve a lot of different type of
complex results based on this usage of case when, then, and end keywords in the SQL statement. So
guys, hope you understood these three examples that I gave for you to make understanding how to use
this case when, then, and end keywords in the SQL statements.
So that's it, guys. See you in the next video session. Thank you. Bye.
Part 80:Delimiter
Hello, everyone. Welcome to part 80. of SQL for beginner series. In this video session, I am going to
explain about delimiter.
So what is delimiter? What is delimiter? In order to understand delimiter, we have to understand the
below things. That is the default delimiter in SQL is semicolon. Okay, semicolon. what is the symbol for
semicolon, guys? This is the symbol, okay? We generally use the semicolon symbol, this one. This is the
symbol for the semicolon, which is the default delimiter in sql statements. Suppose, an example, let me
take an example, okay? Select star from customers. If I say select star from customers, here, this is the
sql statement. At the end of the sql statement, we generally use the default delimiter, that is semicolon,
okay?
default delimiter is generally used at the end of the SQL statements. Here, to end the SQL statement,
this particular SQL statement like select star from customers we have we have used the semicolon
default delimiter. But if you want to change this delimiter, okay, if you want to change this, instead of
using this semicolon, instead of using this semicolon, if you want to use some other simple in the place
of semicolon, okay, here select star from customers have used and there is a semicolon to end this
statement. But instead of this semicolon, if I have to use a different symbol, let's say I would like to use a
double slash symbol or I would like to use a dollar dollar symbol or I have to use slash slash symbol.
These symbols have to work as a delimiter instead of this default delimiter. The same thing that is being
done by the default delimiter. In place of that, I am going to change the symbol and the statement
should work. Is it possible? Yes, guys, it is possible. How to change the symbol? How to change the
default delimiter to another symbol? Default delimiter symbol is semicolon. Okay. But I would like to
change the delimiter to double slash, let's say. So, in that case, I have to write this. Delimiter change to
double slash. So, default delimiter is semicolon. I am changing the delimiter to double slash. After this,
okay, if I say select star from, okay, customers.
In place of semicolon, in place of semicolon here, I can use double slash. Okay. This will work as a
semicolon. Okay. You have changed the default delimiter symbol that is semicolon to double slash here
using this statement delimiter double slash. Then you can use the statements. You can run the
statements and this will act like a semicolon only. Okay. So let me show you these things in a practical
way. For example, we have four divs here. One I have created and other came by default in the MySQL.
Fine. I will use something which came by default in the mysql that is world DB. How to use that? I have
to use, I have to say use world. Okay. When I say use world and run this, this particular db will get
selected and i am free to now perform operations on here any of these tables that are there under the
world DB.
Okay. Now what i am going to do is i am going to use the city. Okay. Generally, the default delimiter is
semicolon. So I will check whether the defaults delimiter is working or not. Select star from city if i say
and put a semicolon here. This is a default delimiter and it will be working. Run this. It is working. Okay.
Now, instead of this, I would like to do something like this. Select, instead of semicolon, I would like to
give double slash here. Okay. I would like to give double slash. By default itself, you are getting error
guys. Okay. You are getting an error. But how to make this work? In place of semicolon, being used as
default delimiter, I would like to use double slash.
Is it possible? Yes, it is possible. So, directly if you give, it will not work this. Instead of semicolon, if you
give double slash, it will not work. How to make this work? Before this statement, I have to write
delimiter double slash. Now, see what happened. The error has been gone and you have to select these
two things and run. It is working.
So, with the delimiter, with the changer delimiter from sell me column to double slash, it is working.
Not only double slash, in place of this, if I use, in place of this double slash, if I want to use dollar dollar.
Okay. Will this work? Let us see whether it will work or not. It is not working. I am getting an error.
Okay. So, it is not working. So, instead if I say delimiter dollar dollar. Okay. And run this. It is working. It
is working now. Now I would like to change the delimiter option to some other symbol. Like I would like
to use hash hash. Here also I am giving some hash hash as delimiter. This time it will work. If you don't
change it, it will not work. So run this. Like this we can change the delimiter default symbol from
semicolon to some other symbol guys. Some other symbol we can change. Then after changing the
delimiter for example, here the default delimiter is semicolon, right? Then you have, for executing this
particular statement, you have changed the delimiter to double double hash and it is working.
After this, if i run select star from city semicolon. Will this work or not? Originally, the delimiter was,
default delimiter was semicolon, right? Default delimiter was semicolon. But I changed the delimiter to
double slash symbol. Now, will this statement work or not? It will work guys. Okay. Even though you
change the default delimiter to some other symbol, it will work. You see it is working. Okay. So,
whenever you want to change the, okay, use the, use some other symbol in place of the semicolon, you
can mention like this and use and still semicolon will work. Still semicolon will work guys. Okay. Next
thing is where exactly we are going to use this delimiter. Why we have to change the symbol? Okay.
Why we have to change the default delimiter from semicolon to some double hash symbol?
What is the purpose? Okay. So, we need to use this delimiter. We have to change the symbol of this
semicolon to some other symbol in case of stored procedures. Okay. In case of stored procedures, we
have to use this delimiter concept of changing the default delimiter from semicolon symbol to some
other symbol. Okay. Anyhow, how to use this delimiter with stored procedures and why we have to use
with stored procedures. All those things I am going to explain in the next video session. For now, just
understand how to use, what is, let's, for now, just you need to understand what exactly is a delimiter,
what is a default delimiter and if you have to change the default delimiter to some other symbol like
double slash or double hash or double dollar, okay, what we have to use, okay?
That's only that you need to understand as part of this video session, guys. In the next video session, I
am going to explain to use this delimiter with stored procedures. Okay? So that's it guys. See you in the
next video session. Thank you. Bye.
So in this video session, I am going to explain how to use delimiters while creating the stored
procedures. The main topic, is the main topic delimiters or is the main topic stored procedures? The
main topic here is delimiters guys, not stored procedures. I am going to explain how to use delimiters
with stored procedures, okay?
How to use delimiters with stored procedures, I am going to explain. And also, at same time, the stored
procedures. Stored procedures. are related to PL SQL, okay? They belong to PL SQL. What is PL SQL? PL
SQL is an extension of SQL, okay? After SQL, people go for PL SQL if you are a developer okay if you are a
developer and SQL will have only single statements, okay? Single commands or statement kind of
statements will be there, right? Queries will be there. Single query statements are nothing but SQL.
Select star from employee, okay? And insert into. table, values like that. Those are the SQL statements.
But coming to PL SQL PL SQL is nothing but the full form is programming programming language in SQL.
Using this SQL statements we are going to write programs. We have to write some programs here. Some
logic we have to write. Like what will be the general programming languages for example if you take
Java. Java is a programming language. What will be the basic thing? Variables will be there. Okay, then
literals will be there how to how to create the variables, how to assign this very literals to this variable.
Literals means values, okay? Then we have uh what you call selection statements will be there like if if
condition and all those stuff okay if else if uh okay uh switch case like that control flow flow statements
will be there they are like while loop, do i look for loop, okay? All those things.
then lot of other concepts like functions, constructors. Okay. This all, all generally belong to a
programming language, Java. Similarly, in case of SQL, we have a programming. Okay. If we have to do
some programming with SQL, we have to, we cannot use java case. Okay. I cannot use java for
programming the SQL. So what i have to do, there is a dedicated language. Okay. Which can use the sql
query statements inside this programming. Okay. Such kind of language is nothing but tl SQL. plsql it has
its own syntax. Like Java has its own way of creating the variables, assigning the literals to the variables,
creating all these kind of statements and all similarly plsql has its own way of, okay? Its own way of
representing all this stuff plsql means programming language in SQL.
Okay? So, and this stored procedures belong to plsql okay this stored procedure concept belongs to
plsql here In Java, we have functions, okay? For if you want to repeat the same, okay? If you want to
execute some set of code, okay? And multiple times if you want to execute, sometimes like frequently
are going to use that set of lines of code, okay? So what you will do, instead of repeatedly writing the
same lines of code again and again, you will create the functions. You can call the functions. Whenever
you call the functions, that particular set of code will be executed. Similar way, in PL, SQL, the stored
procedures are nothing but functions kind of thing in Java, okay? They are like functions or methods
case.
They are functions or methods, okay? So stored procedures are like functions or methods in other
programming languages. So if you have some code which you need to call repeatedly at later point of
times, then you will create a stored procedure that is function or method for that particular statement
which you have to call multiple times, okay? So stored procedures. And in this video session, I'm not
going to cover PL SQL. PL SQL is out of scope for this video session, okay? Video course. So hence, I don't
want to focus my explanation on stored procedures, okay? Because stored procedures belong to PL SQL
and you have to learn the programming like variables, creating the variables, assigning the literals. This
is a very, it's a different world altogether, guys, okay?
I cannot explain all this PL SQL concepts as part of SPL. We can create a separate course on PL SQL if
required, okay? But this is mainly required for developers, guys. If you are a pure developer, Okay? If
you are not a beginner and if you just started you have to start learning with SQL. Later point of time
when you move to a complete development road role and that too you have a requirement of and that
too you have a requirement of programming in plsql then only you have to learn this plsql otherwise it's
not required. And also at same time if you are a software tester Okay? And to what extent we need to
learn? If you are a software tester you have to learn only SQL.
Okay? SQL will be enough ways. No need to learn plsql You're not going to do any programming around
SQL. So PL SQL is not required for software testers also. Mostly they require SQL only. Mostly they will
require SQL. Fine. Now, next thing is I would like to demonstrate, I mean practically demonstrate how to
use delimiters with the stored procedures. That's the main topic, guys. PL SQL stored procedures are out
of topic for this session. Uh, you need to know some small basics about stored procedures. Anyhow, I'll
explain that, okay? They are like functions or methods in other programming languages. If you have a
code which need to be repeatedly executed, then what you will do, you will put that code into the
function in the programming language.
Same thing here also. If you have some sql statements which are to be called multiple times or
repeatedly called, such kind of sql statements you can put inside a stored procedure. And this stored
procedure can be called. We can call the stored procedure, guys, okay, at later point of time. So, in this
video session, I am going to practically demonstrate how to use delimiters with stored procedures and
what is the requirement of using the delimiters with stored procedures. That is the main topic, okay?
Not stored procedures. Fine. Here, we have the qfox database, which is by default selected that's fine
but uh yeah i would like to work on this world database guys okay? There are four databases here, as
you can see here, QFox, agilases and world.
so this is created by me in one of the previous videos, but coming to circular assist and world, okay? This
came by default with the MySQL. So which came by default with the MySQL, world is also came by
default with the MySQL. I would like to use this world, okay? World DB. How to use that? How to select
that? I have to say use world. Then, then run this. Then world db will be selected. World DB will be
selected. After selecting this world DB, okay? Then I can perform any operations on any tables here.
What are the tables that are existing in the world database? I can perform after selecting the world
database, I can do any operations on the tables which are under the DB.
That's fine. Now, next thing is how to show you the requirement for using the delimiters with the stored
procedures. Let me start writing a stored procedure now. Before starting writing a stored procedure,
which statement I am going to use is city table. I would like to use a statement like select star from. city
any statement some sample sql statement i am taking that is select star from city if i run this all the
details like this okay from all the columns of the city table will be displayed here right this particular
thing i would like to keep under the stored procedure so now let me create a stored procedure create
okay this is the syntax for creating the stored procedure guys you don't have to learn but uh let me
explain create procedure okay create procedure procedure name
let's say a procedure name is like a function, guys. The kind of function, generally how the type of
functions will be. There, in one of the previous videos, I explained there are different type of functions,
built-in functions in MySQL, right? Like max function, minimum function, okay, count function. this is
syntax. This is how the functions will look like. Similarly, stored procedure is also a function. So, which is
manually created function. We are manually creating it. It's not built in for MySQL. Whatever the
function i am going to give, this is not there in the MySQL, guys, okay? So, max, min and count are the
built-in functions. But coming to create procedure, get all cities. Like this, I created some user-defined
function with my own way.
You can give any name here. So, similarly, I give that kind of name. Create procedure, get all cities. Here,
you have to start the procedure. This is just the definition of the function. Create procedure, procedure
name. That is function name kind of thing. Then begin. Begin. And here, I have to say end. okay begin
and end here i will write a statement like select this statement i will copy paste here okay nothing but so
this is just this is the starting of the function begin means starting of the function end means ending of
the function okay inside this function select star from city is there okay so that's fine i have to put a
semicolon here there are two ways right semicolon is there semicolon here but i am getting some errors
guys the problem here is
The problem here is without delimiter, these procedures cannot be created. So, I have to create the
delimiter. Delimiter double slash. I am saying double slash. In the previous video, I explained about the
delimiter. If not, you can just go back to the previous video and understand why delimiters have to be
used. Delimiter double slash. I am saying the default delimiter is semicolon. I want to replace the default
delimiter with this double slash. So in place of the semicolon, I'm going to use double slash. Here, when I
said delimiter double slash, here I can use double slash, okay? Here I can give double slash. At the end of
the stored procedure, I'm giving the double slash in place of semicolon. In place of semicolon, I'm giving
double slash.
Inside the statement, I'm giving the same semicolon, guys, okay? So here double slash can also be used
in place of the semicolon, okay? So, for one of the semicolon, I use double slash. There is a reason guys.
There is a long big story behind this why we have to use del meters and all. Okay. If you want to put this,
if you want to send this complete code, SQL code to the server directly. Okay. To the server directly and
MySQL don't have to interpret each and every line. Okay. Very technical guys. You don't have to
understand that. Okay. If you are creating a store procedure in order to avoid the errors, you can simply
in our case. Okay. We can simply use delimiter like this, okay?
Delimiter double slash and in place of one of the semicolon which is at the end of the procedure, just
replace that with a double slash. This will be enough. This is the way to use the delimiter with the stored
procedures. Now, if I create this, what will happen? A function that is a stored procedure will be created.
So far, you see under this, there are no stored procedures, right? Under this, under world DB, there are
no stored procedures. This stored procedures section is empty. after i run this okay after i run this now
refresh you see get all cds stored procedure got created it's a function guys it's a kind of function and
while creating this function while creating this function we need to use this delimiter otherwise if i don't
use what will happen i'm going to get errors like this okay to resolve these errors i have to use delimiter
okay here i have to say semicolon here okay but still the problem is not getting resolved so it's a
mandatory to
provide the delimiter. That's the reason i am using delimiter, guys. You don't have to worry too much
technical details about why we have to use delimiter here. Find delimiter double slash, create
procedure, get all cities, begin. Select start from cd end with the delimiter symbol. So, this stands for
semicolon itself okay this this also works like a semicolon. Now, this total section will be sent without
interpreting the each and every line. Total section will be sent as a function. Okay? To the server or
whatever it is. Now, Anyhow, the procedure got created here. Stored procedure got created here and it
got displayed under stored procedures of this DB. Fine? Now, how to call it? How to call it? There's
something called call. Okay?
Call this function, this stored procedure. This is a stored procedure guys call get all city stored
procedure. Okay? So, instead of running this sql statement every time, you can simply call this get all
cities automatically inside this select star from city will be running. Okay? Run this. You see? whatever
the result you got with select stars from city, when you call this stored function, the same thing will get
executed. No matter how many times you run, the same set of uh SQL statements which are there inside
this uh stored procedure can will be will be executed you can you can write any number of lines of code,
this In general, if you go with the PL SQL, right, okay, you can, you have a lot of uh you have a lot of
other keywords coming, PL SQL.
This not, declare is not belong to SQL, guys. It's a PL SQL, programming language. Declare, Any variable
name you can give, like country, data type you have to specify, like this. Like this, lot of things are there.
You can create a while loop and all those stuff. So in between the beginning and end, you can write any
number of statements inside this stored procedures. And this call function will simply call this function.
There's a lot of things that you can learn about stored procedures, guys. But I'm not explaining because
stored procedures belong to PL SQL language, not SQL. They belong to PL SQL. It is a programming
language. You can pass some value to this particular stored procedure function. Or you can get some
value in return while executing this function.
Everything is there. Whatever that you can get out of a function in Java programming that you can get
with the stored procedures. But this is out of topic for us guys. PL SQL is not in our video course. So I am
not covering it. And it is also, it is only required for the pure developers who have the requirement of,
okay? You have the requirement of writing the programming using sql statements, okay? For them only
it is required. For remaining people, you don't have to learn. SQL will be fine enough, okay? You don't
have to worry about that. So guys, this is all about how to use delimiters okay while you while creating
the stored procedures. Here I explain how to use delimiter while creating the stored process while
creating the stored procedure i need delimiters, right?
Here, delimiter, double slash, double slash. how to use it? Okay, this is the way of using it guys okay fine
guys uh so that's it, guys. See you in the next video session. Thank you. Bye.
Part 82:Views
Hello, everyone. Welcome to part 82 of sql for beginner series. In this video session, I am going to
explain and practically demonstrate on how to use views in sql statements. So, in this video session, I am
going to explain about the usage of using sql statements First, we need to understand what is the
purpose of views. What is the purpose of using views in SQL statements? We need to understand first.
So what exactly are views and what is the purpose? You have to understand. Now to understand the
purpose of views, let me explain something.
Let's say there is a table, guys. Let's say there is a table. And it has some columns like this. Some four
columns are there in the table. And I am giving the column names as C1, C2, C3, C4. And let us say the
table name is Table 1. And it has some data. Under the table, there are some records. There are some
column records are there. Some data is there under all the four columns of this particular Table 1. There
are some data. That is, table records are there. That is fine. Now, tomorrow... What happened is we got
a requirement where we don't want to display this entire table on the web page. Okay. And we wanted
to have only first three columns.
We don't want this fourth column. So that another requirement came. So I cannot use this table, right? I
cannot use this table one because this table one has C1, C2, C3, C4, but only up to here I want. I only
want up to here. Okay. Without deleting this table or creating the table again with this kind of thing, I
cannot do, right? Okay. Only these three columns are needed. What I will do? Tomorrow what I will do is
I will create another table. Let's say table 2. And this time I will create the table with only three columns.
Only three columns. The required columns. So here it has only the first three columns. That is C1, C2. C1,
C2. And C3. Again tomorrow.
Another requirement came. So where I have to create another table. Table 3. It should have only C1, C3,
C4. C2 column should not be there. Like that another requirement came. Again another table we will
create. And it will only have again 3 columns. A different set of columns will be there here. The column
names will be like C1, C3, C4. like this so based on our requirements we need to create this is the same
C3 is in this table. All these things, all the new table columns are already there in the first table. But since
there is a small requirement changes like this column should not be there or this column should not be
there, we have to create this kind of different tables. That is a problem. And one more situation will
come there. We have two tables. So this example is done. Why we need views? Because Every time we
need a small change in the existing table, we need to create a separate table. Let me write down here.
Every time we need a small change in the existing table, what we have to do? We need to create a new
table. For every small change, that column should not be there.
This column should not be there. For every new change, we have to create another table. Do we have to
create like that? not required, right? Because, so, uh, for, uh, because all the columns are there in the
main table, original table, okay? The first table. All the columns are there in the first table. Why should i
create more tables? Just for the small changes like fourth column should not be there, second column
should not be there in the resultant table, okay? There should be some solution, right? The solution is
nothing but views, guys, okay? Using views, we can overcome this problem. I'll explain. Later point of
time, I will explain how to use views, okay? For now, understand the requirement, why we have to
Use views in the SQL statements. First, just for the small changes in the table, we don't have to create
multiple tables. For different categories or types of the tables, we don't have to create multiple tables.
Just because of the smaller changes in the number of columns and all those stuff. There is a solution for
that. That is nothing but views. Another place where we need views are, let's say there is two tables.
There are two tables. In one of the tables, there are three columns like this. The first column has a name
as ID. Here, name. Let's say this is an employee table. Let's call this EMP1 table. EMP1 table. This is an
EMP1 table. Here, columns are ID, name, experience. ID, name, experience.
And there is another table which has like this kind of columns. Again, here also we have ID. And here we
have country. and city. Okay. Country city. This is also employee table but a different employee table.
EMP2 table. Okay. So in the first employee table we have id name experience columns and second
employee type of table we have id country city. But what happened is tomorrow you got a requirement
where you need a table. Okay. You need to create a table in such a way that it has this number this type
of columns. Okay. It should have these columns. That is It should have ID. It should have name. Then it
should have experience. It should have country. It should have city. It should have country and it should
have city.
country and city. Like this, I want another table. Okay? The requirement came where we need to create
a table something like this. But in the database, already there are two tables. Two different tables are
there. One table already has id name experience that this required table has. And another table has id
country city. ID country city. Now, how to get this table? I have to create another table, right? I may
have to create another table like emp3 in real time. But why do we have to create more number of
tables? Already we have all the required columns and data in the existing tables in the database. Again,
just because of this kind of requirement where we need all this different number of columns that are
there in both the tables, why we have to create another table?
To overcome this problem, we have to use views again. We have to use views. So using views, what we
can do is we can get the records from both these tables. Okay. And, and we don't have to create, okay,
the solution. So for every small change in the existing table or tables, we need to create a new table.
This thing, to overcome this kind of problem, we need to go for views. Using views, we don't have to
create new tables unnecessarily. Okay. So what is the purpose of use now tell me. To conclude, okay,
using views, we can overcome the need for, the need for creating more tables. Okay? Creating more
tables okay instead of i mean uh using views we can overcome the need for creating more tables.
Even though, even though the required columns and data are available in the existing tables. Even
though the required things are there in the existing table, but Just to get that five columns or less
number of columns or more number of columns from different tables or from the same table. Okay. We
need to create multiple tables. Right. In order to overcome this, we have to use views.
We have to use views. What views will do? Okay. What views will do is like they will create a replica.
Okay. Kind of replica kind of thing. Like, for example, you are the person here. Let's say you are the
person. This is you. and there's a mirror mirror before you, okay? So when you stand before the mirror,
what will happen?
The same copy of you will be displayed in the mirror, right? So views are something like this, guys, okay?
This is a table. And using views, we can create a mirror image, okay? In whatever one uh the way we
want to see. There are some different type of mirrors right like uh okay which have the extra capabilities
like that, okay? So this mirror views are like, you can display multi different columns from different
tables into a single table kind of thing, okay? That is also possible, okay? Or if you have a single table and
in that, instead of these three columns, you want only id and name. That also can be displayed self of
use okay? It's a magic kind of mirror, guys.
Not a straightforward mirror. It's a magic kind of mirror where even though you are thin, you can look
fat or even your fat you can look thin, okay? Something like this. So even though this particular table has
three columns, in the mirror, you can display two columns, okay? Or as it is also possible, as it is,
whatever you are, as it is if you want to get displayed also is possible, okay? So, again, again, if i have to
explain about views okay we have to explain about views in a different way, views are nothing but the
virtual tables. Views are nothing but virtual tables, guys, okay? They are not real tables, but they are
created out of the real tables, okay? here we have real tables.
Instead of the need for creating a new table, just because this tables doesn't have the require all the
required things, okay? Like that, okay? So, what we are going to do is, we are going to create some
virtual tables using the existing tables so that our requirement is satisfied. We don't have to create
multiple tables or more table necessarily. Instead of that, if we use views, right? Okay? We can create a
virtual tables, okay? This is a real table. Let's say this is a real table. This is a real table. and you can
create a virtual table based on your requirement in the application. So that is nothing but views. Now,
one more advantage you get from the views is like, let's say on a web page you went to an application,
web application, in that there is some data displaying, okay?
There is some table data displaying, like uh data is something like idea of the employees, employee
name, okay, employee salary, employee experience, all those details are getting displayed. Okay? There
is a page. So, this person, this person who is actually viewing this particular table on the ui of the web
page doesn't know that at the back end there are two tables. Okay? He doesn't know that, this person
doesn't know that all these columns are not from a single table. He doesn't know that. Okay? There is a
line of separation. Okay? This person don't know the internal working of the db in the db in the database
the database, there are two tables okay table one table two from these two tables, we can display, on
the web page, we can display in a single table all the required details for this particular person.
This person will think that there is only one table inside but uh internally there may be two tables, three
tables, four tables. We don't know. But in the output, that is on the ui of the application web page, it's
being displayed as a single table. This is only possible with the help of use case Okay? Views. We don't
have to create tables for this kind of requirements. Today, you may need four columns. Tomorrow, you
need five columns. Day after tomorrow, you may need seven columns or eight columns or nine columns.
But every time for a small change, you don't have to create multiple tables for six column table, seven
column table. It is not required. Rather, what you can do is you can simply create views.
That is, you can create the virtual tables using the existing table records. Then display it in whatever way
this particular person wants. That this is the main reason, guys, why we have to use views, okay? you
understand this concept, okay? you understand this concept. Practical understanding will be very easy.
So, next thing is,
let's go to the practical mode, guys, okay? Whatever I explained so far, like uh creating views from a
single table or creating the views from multiple tables, whatever it is, I'm going to explain in a practical
way now. So, how to practically demonstrate is, I'm going to use this database QFox, okay? Current
selected database is world. But if I have to create some new tables or modify new tables or work with
the tables under this particular QFox database, then I have to select this particular database.
And for your more information, there are four DBs here, right? So these things, these three DBs, Satellite
Analysis and World Databases came by default in the MySQL. But coming to QFox, this is created by me
in one of the previous videos. So I'm going to use a database created by me. So how to use that? I have
to first select the database using this use QFox statement. So when I run this, this QFox database will be
selected. Once this QFox database is selected, what I'm going to do is, there are a few tables which were
created as part of the previous videos or whatever it is. So select everything and just delete them, drop
them. I don't want any tables to be there in this database.
They got cleared it. Now there are no tables under this QFox database. So I'm going to create new
databases. So, first database i'm going to create is create table okay parallel i will show you what's
happening in a diagrammatic format so that you can understand the things in a better way. Okay. So,
close it. It's not required uh fine so uh whatever i'm going to practically demonstrate it, I'm going to
diagrammatically represent at the same time. First, what i'm going to do is i'm going to create a table,
guys. Okay. The table is emp one table emp one table so it will be like this. It is going to have three
columns, guys. EMP1 table is going to have three columns. The first column is id column, ID of the
employee.
Then second column is going to have the name third column is going to have the experience okay third
column is going to have the experience fine in this some four records i'm going to insert. Okay, in this i'm
going to insert. Some four records. So, I need another extra record here. Four records I said, right? This
is extra record. This table has four records. One, two, three, four. So, in the first record, I am going to
give one, Arun. Experience as 12. Then, second one is two. Then, Varun. Experience as seven. Then,
three. Tarun. experience as 9 the fourth one dinesh the experience as 11 okay like this, four uh records
are there is this emp1 table that i am going to create practically.
I have to create the data, right? In order to explain views, I have to set up this kind of tables then only i
can explain so let me let me create this table and based on that, I can explain views later point of time.
So create table. What is the table, guys? EMP1 table. Okay, EMP1 table. the records are, like, the
columns are id as in name as worker and uh the experience has uh inter okay like this i created a table.
So I have to run this first, okay? Then only the table will be created. So once the table got created,
refresh here. You can see the table here, emp1 table got created and uh whatever the columns i
mentioned, those will be there under the columns.
You can see here. Id, name, experience are the columns in this emp1 table. Now after that, I'm going to
insert some records into this table. by default, when you create a table, you will not see any columns. I
mean, you will not see any records. If you say select star from emp1 empty table will be displayed with
the only the column names, okay? Without any records. You see, ID, name, experience columns are
there without any records. Now, I have to insert some records into this table. How to do that? Insert
into emp1 values as values as one comma, same records i'm going to insert, guys. one around two
around seven three around nine and four finish eleven okay? one around 12. Insert into EMP1 values as
2.
Varun. Experience as 7. Insert into EMP1 values 3. Tarun. Experience as 9. Insert into EMP1 values 4.
Dinesh. Experience as 11. Like this I will insert four records into the table. So after inserting these
records, let me say select star from EMP1. You see all these four records got inserted into the table.
Now we have a table. EMP1 table. So on the top of this table, okay, I'm going to apply views. How to
create views? I don't want, there is a requirement. Let's say this is a real table. This is a real table. Okay.
But tomorrow a requirement came where I need to create a table. i need to create a table which has
only id and name only a table need to be there we should have id and name guys okay only id and name
should be there that is the requirement for that i don't have to create another table rather i can create a
view for the same existing table and use it as a another table and display it to the people okay that is
better right rather than creating multiple tables just for the small sake of the requirement changes okay
so what i'm going to do is i'm going to create a view which will only contain this
based on this emp1 table, I'm going to create a view, which is nothing. View means what, guys? Virtual
table. Okay? Instead of creating a real table, I'm going to create a virtual table based on the existing
tables, based on the changes requirements. That table is going to have only idea and name. Okay? How
to do that? Create view. I have to give the view name, guys. What is the view name? emp1 view. Okay?
emp1 view. So, create view, emp1 view. As, I have to use as, select star from EMP1. What will happen if i
do so? All the columns from the emp1 table will come into the emp view, okay? I don't want all the
columns. My requirement is to only have the id and name, not experience.
So instead of asterisk symbol here, I will say id comma name now what i am going to do is, this is a this is
enough guys create view the view name. the view virtual table or view that you are going to create, its
name is going to be emp1 view. Okay. Which is being created on the based of EMP1. Okay. I have to say
create view view name as select whatever the columns that are needed for that particular temporary
table or i mean not temporary, virtual table or okay view id comma name from original table. That is a
real table EMP1. You have to say. Now, if i run this, a view will be created. Okay. A view. will be created.
So, create view got successfully executed here.
Now, how to find? So, how to find the records that are there in this particular EMP1 view? Similar guys,
same thing. Same statement you have to use. Here select star from real table name. Here you will say
select star from view name. If you say select star from view name is EMP1. Newly created view name is
EMP1 view. Okay, EMP1 view. If I run this, you'll get all the records that are actually there in the EMP1,
but only from this id and name column because here i clearly specified create view emp1 view as select
id comma name from EMP1. Only ID and name will be coming from this emp1 table into this emp1 view
with all the records though. Okay, if i run this, you see all the records, one, two, three, four records
came, but columns are only two columns, not three columns.
In the real table, we have three columns. The experience is also there. but we got a requirement where
we need a table where only id and name should be there. For that reason, I don't want to create
another table. Rather, what i will do is, using the existing table, I created a view with a different name,
okay, in that i specified it should only have the id and name. Every data we got, but columns are only id
and name as per the requirement. Like this, guys, this is the purpose of views, okay? Now, tomorrow,
something happened that there is a requirement, uh, let's say there is a requirement came where on the
web page, okay? On the ui application web page, they wanted to have a particular table to be displayed.
That table should have the employee details, okay? The same employee details, whatever that is there
in the mp1 table, right? The same employee details are required to be displayed on this table. But all the
employee details should be, okay? All the employee details should be uh greater than uh greater than
10 let's say okay only greater than 10 whose experience okay All the implied details whose experience is
greater than 10 should be displayed on this particular table of this webpage. Again, do I have to create
another table? Right. I don't have to create another table. Even you can simply say select star from. That
is also enough. But if there is a requirement where we have to show it as a table.
[Link] we can do is we can create a virtual table for that. Okay. For this also we can create it. There
is a possibility of creating a virtual table. Okay. So what I will do here is create view. okay create view
emp1 view b so just to differentiate with this emp1 view i'm just giving employee emp1 something b
letter i'm adding so that this name will be different from the earlier view okay as selector id comma
name comma experience okay from table name is original real table name is emp1 where i will add Here
also I can create a view like this also. So where experience is greater than 10. So whatever the virtual
table that is going to be created based on the existing table, that table is only going to have the records
of the employees whose experience is greater than 10.
Instead of creating a new table of the employees whose experience is greater than 10, what I am doing, I
am creating a new view which can create a virtual table. So, with the details of the employees whose
experience is greater than 10. This is a better way. Instead of creating the table, we have to do like this,
guys. Okay. That's the only thing. Nothing more than that. Run this. So, there is some problem here.
Unknown column experience. Maybe I have given some spelling mistakes maybe here or here.
Experience. Okay. Select ID, comma, name from emp1 where experience. Yeah. Here. Here is the
mistake. Okay. I have to give EXPE RINCE, that's fine. Now let me run again. Now the view got created,
new view with the name EMP1 view B got created.
So how to find the details in that particular table? You have to say select star from, okay? Select star
from EMP1 view B, okay? If I run this, we'll see a table which is according to our requirements. That is ID
name experience columns are there. But only two records are there having the experience greater than
10. So in real time, we may get different type of requirements where we need to keep on creating
multiple tables from the existing tables. Instead of creating more number of tables, simply we can create
the views. Just to avoid creation of the new tables unnecessarily, we can create views which are nothing
but virtual tables of the existing real tables. So, the requirements may be anything, guys. These are two
examples, two cases i explained, right?
One case where you don't need all the four columns, only three columns are required. In another case,
there was a requirement where the experience of the employees greater than 10 only should be
displayed in that particular table. Okay? Like that. Based on the requirements, we don't have to create
tables, guys. We can simply create the virtual tables using the views, which will solve the problem. Fine.
Now, here, whatever i explained so far are based on the single tables, right? These are all based on a
single table, but let's say there is another requirement where, okay, there are two tables, okay? Here
only one table is there, but there may be some other cases where in the database, this particular table is
in the database, okay?
So DB, okay? DB. In the DB, there are two tables. Another table is there here. This table name is emp2
table. emp table this is also a real table one more real table is there that is emp2 okay here real table is
emp1 here also another real real table that is emp2 is there here also we have id of the employee and
here we have country country is there now the requirement is so but this only has let's say only three
records are there here four records are there in the emp1 table but here in the emp2 there are only
three records Now here ID is 1, 2 is there, 3 is there. So here country I am saying India, USA and UK.
Fourth record is not there here. Only in the EMP1, 4 records are there. EMP2, only 3 records are there.
In this kind of situation, there came a requirement where a table should be displayed on the web page.
to the real users on the your application of the web page where these details should be displayed. That
is ID, name, and country these three three columns should be displayed. That is ID, name, and country.
So here name is from one column. I mean, ID and name are from this emp1 table. in even id is common
between emp1 and EMP2. ID is common between common with the emp1 and EMP2. But coming to
name, name belongs to the mp1 only here this emp2 table doesn't have the name.
But country is belonging to the mp2 which is not there in the mp1 but the resultant table that is needed
to be shown on the web application for the real user is only the three columns table. ID, name, country.
But here, I cannot take this table directly or i cannot take this table directly. What I have to do? I may
have to create another table. But creating tables unnecessarily even though you have the this kind of
tables available in the database is not good. So what we have to do, we have to create virtual tables
using views. Okay, we have to apply views where with the help of views, we are going to, okay, display a
virtual table based on the required internally.
There are two tables, but here we are going to show that as a single table to the user on the application.
So with the help of views, that's possible. Instead of creating a new table, we'll do like that. So here, But
the problem is if I have to display ID name country, country is only there for three records. So only three
records should be possible. Okay. So what I'm going to do is I'm going to compare if the ID of this
employee one is equal to the ID of the employee two, then only display the records. Such kind of
condition if I keep right, only three records we'll get. Otherwise, we'll get a mismatch of the two tables.
Okay. We should have a condition where
Okay, we should have a condition where if the id of the employee1 is equal to the id of the employee2
then only display the records from both these tables. Otherwise, don't display. Like that kind of
condition, if i keep, then things will be good, guys. Okay? So let me practically show you how to do that
before before creating a view, we have to create this emp2 table guys we have we already have emp1
table in our database, but now we have to create the emp2 table in our database. How to create that
emp2 table? You have to say create table EMP2. Okay? here i will say id int and country as varchar,
okay? varchar of 15 or something. Done. Let me create this table.
A new table will be created with emp2 name. By default, it will be an empty table, guys. If you say select
star from emp2, what will happen? Empty table will be displayed with only the column names,
okay? Empty table with the column names will be displayed. You see? column names are id country and
under that no records are there. Now let's insert some records uh let's insert only this first three records
guys. Okay. So one two three not four we leave it. So insert into emp2 values as one comma country i
am giving India. Okay. So then insert into emp2 table values as two comma USA. Then insert into EMP2
values as 3, UK. Like this 3 countries I gave. Now insert all these records at once.
All the records will be inserted. Now select star from EMP2. This time you will get 3 records inserted into
this ID country columns of this particular EMP2 table. Now we have 2 tables guys. This is how we have
the tables. EMP1 table has ID name experience with these 4 records and all these things and EMP2 has
the 2 columns ID and country with all these records. Now, I need something like ID name country. The
requirement is to display something on the web page. So, with the help of views, instead of creating the
table, with the help of views, we are going to create a virtual table out of these two tables and create
the resultant table. How to do that? I have to say create view, create view, EMP view.
I am simply giving EMP view as here We already know how to use two tables. How to use two tables in
the select statements, we already know. I have already explained this particular topic in the previous
videos. In one of the previous videos, I explained if you have two tables and if you want to retrieve the
records from the two tables in the single result, we can use select statements. Select what is required. ID
is required. Name is required. Country is required. ID name country. Here, there is an ambiguity, guys.
The ambiguity is ID is common for both these tables. EMP1 ID is there. EMP2 ID is there. So if I run this
kind of statement, I will get an error saying ambiguity error.
So to overcome that, I have to give the table name here. I will give that soon. From EMP1 comma EMP2
tables. So here I am specifying EMP1 comma EMP2 tables. Two tables I am going to retrieve the records
of ID name country. Name belongs to EMP1. Country belongs to EMP2. but id belongs to both emp1 and
EMP2. So instead of what i'm giving i'm giving [Link] okay one of the table i'm mentioning. You can
even give emp2 also. Not a problem. Okay. Anything is fine. [Link]. So from one table, this ID. Because
this id is there in both tables, better to give one table as reference. And here i'm going to add a
condition like where [Link] is equal to [Link]. So if the id is matched then only
You have to retrieve the records. Otherwise, don't retrieve. Here 1, 2, 3, 4 are there. Here 1, 2, 3 is
there. Here 1, 2, 3, 4 are there. Here 1, 2, 3 is there. 1, 2, 3 should match with 1, 2, 3. But 4 will not
match. So this record will not be considered for this particular table. Only 1, 2, 3 records with Arun,
India. 2, Varun, USA. 3, Tarun, UK will be displayed. But 4, Dinesh, nothing is there here. So it will be
ignored. So this particular table will display only 3 records from 2 tables. So this is how guys we have to
take care of the things. So here, if I don't give EMP1 here, we will get an ambiguity error because ID is
there in both the tables.
So you have to mention one of the table name before the column so that it will be cleared. So run this
now. So the view got created with the name EMP view. So we have to find out what is there in that EMP
view. Select star from EMP view. If I run this, you'll get the required result. Okay. of the table, which has
three columns, ID, name, country. Okay. ID is one two three. Name is from first column, first table. That
is the employee one. Country is from the second table. That is employee two okay dmp2 so one two
three, Arun, Varun, Tarun, India, usc Okay. Whatever the result we want, this table, now i am going to
show on the web page of the application.
Instead of, this is not a new table, right? This is not the real table. It is a virtual table. Okay. Created by
the views. Okay. With the help of views, we got the virtual table rather than every time creating the new
tables. the databases fine so so this is how guys we can use uh simple views and complex views. Simple
views is something where only one table will be there you may need you may need only two columns
out of that uh single table. Okay. Whereas complex views are where you have multiple tables and you
have to create another table out of that, another virtual table out of that existing tables. Okay. So, those
are complex views. So, here this is an example for the complex views because
have used two real tables, okay? For getting the view of whatever we need. Fine. Now, one more thing i
need to explain before i close this stuff guys uh let me clear up to here. We only need one table for that
particular understanding of that. What I mean to say here is, if i create a view based on this particular
table, let's say i create a view like create view emp emp1 V, something like that, okay? This is a view
guys. Or we can say view EMP1. So this view I am creating with a purpose as select star from EMP1. So
what will happen? So what will happen if I say create view V EMP1 as, so based on this EMP1 table, this
new view will be created, right?
Virtual table will be created. Let's create. Here I mentioned asterisk this. Asterisk guys. If I say asterisk
means all the columns that are there in the real table will be also there in the virtual table also. That is
also possible. Okay. If I say select star from B EMP1 view. This is a view right. This is not EMP1. It is a
view EMP1. Okay. So run this. The replica of that original real table as form of the virtual table will be
displayed here with all the data and columns. That is fine. Now what if I do some operations on this
view. or what is? Tomorrow, after creating the view. This here guys, we have created the view. Okay.
Now the example here is, after creating the view, after creating the view, if i insert any records into the
real table, okay, on which, on which we have created the view, what will happen?
You are understanding, right? This is a real table. And based on this real table let's say we have created a
view. Okay. Tomorrow, after creating the view, I inserted one more record into this view. I mean, I
created one, I inserted one more record into the EMP1 table. Okay. Here in the original real EMP1 table,
there are four records, but after creating the view here, I inserted one more record, fifth record. Okay.
Then what will happen to the view? View will be reflecting the original real table or what will happen?
Okay. So here, so before, like before I insert any record into this EMP1 table, If I say select star from
view EMP1, I am getting 4 records, right? So, now if I add another, insert one more record into the
original real table, okay?
Like this, 5 comma some Kiran, okay? Kiran. And I will say 8. Like this, I am trying to insert one more
record, 5th record into the EMP1 table. So, if I say select star from EMP1, 5 records will be coming here,
right? 1, 2, 3, 4, 5 are coming. But if I say select star from V EMP1, will there be four records or five
records? That is the thing. Okay. If I change anything in the table, will the view will be changed or not? Is
the question. The answer is yes. Whatever the changes you do to the table, the same will be reflected in
the views also. If I say select star from vmp1 even i am getting the five records. Okay. Even I am getting
the five records.
Let's see what will happen in the reverse way. So if i am inserting something or updating something to
this table, the same thing is getting changed in the view. what if i change something in the view, will the
table will get infected or not? Okay? Reflected or not? That is another question. Reverse way. Okay? This
way, reflection is happening. Right? If you do some changes to the original real table, the changes are
reflected in the views also. Whatever changes you do to the table are there also, applied to the views
also. Okay? But if i apply the changes to the views, will those changes will be reflected in the real table
or not? Is the question now. Backwards. Okay? The answer is yes, guys.
even though you do changes to the views also, the same kind of changes will be applied to the tables.
For example, if i say delete, okay, from v EMP1, okay, EMP1, where id is equal to okay id is equal to 3
from all these records, from the view, from the view, I am trying to delete a record which is having the,
okay, this is a view, right, run this, this is a view, whatever the here we got is a view, okay. In this view,
that is virtual table, ID, ID is equal to 3 column i am id is called 3 record i am removing only 1 2 4 5
should be there after this statement. Run this. It got executed. Now, if i say select star from v emp1 okay
only 1 2 4 5 is there in the virtual table or in the view.
What if, will this change reflect in the table or not is the question. Yes, guys. The same change will be
reflected in the table also. Now, if i say select star from emp1 you will get the same result. Okay. If you
delete a table here, the table will be deleted in the, real table also. If you insert some record in the real
table, the record will be inserted in the view also. So they both are connected guys. Okay? They both are
connected. So changes done to the view or table are same guys. Okay? They will be reflected
everywhere. Just keep that in mind. So guys, these are all the things that you need to understand as part
of the views and how to use the views and different type of views in the sql statements everything has
been explained in this video session.
Hope you understood this session guys. So that's it guys. Thank you. See you in the next video session.
Bye.
Part 82:Indexes
Purpose. Indexes are something that we can create for the tables.
That means we can create indexes for the table. Okay? For the tables. We can create indexes for the
tables. Why we have to create the indexes? There is a reason. Okay? There is a reason why we have to
create the indexes for the tables. By creating these indexes for the tables, it will improve the
performance. Performance, that is the speed at which we can retrieve the records at a faster speed from
the tables. The tables having indexes from those tables we can retrieve the records in a faster way than
the tables which doesn't have indexes.
If you create indexes for the tables then we can retrieve the records from that particular table in a faster
way. So, indexes are something like, indexes are something like, let's say there is a book guys okay
there's a some book is there. This book has, let's say, some thousand pages. Now, if i ask you, if i ask you
to find some word inside this book, okay? Or some topic, some topic inside this book. Let's say this book
is about sql and if i want you to, Find out about the update statement. I would like to find a topic known
as update in this particular thousand pages of SQL book. Let's say this is a SQL book. I would like you to
find this update statement related topic in this particular thousand pages.
What you will do, you will start from the first page. After completing the first page, if you don't find this
update statement, then you will go to the second page. Then third page, fourth page and you keep on
going until you find this update related topic in some of the pages in this particular sql book. But what if,
but what if in the, what if i provide some table of contents? Okay. Some table of contents. Generally
table of contents will be there in every book in the beginning of the, right? Table of contents. So this
table of contents will contain the list of topics that are explained in this particular cook in this thousand
pages now instead of searching this thousand pages if you go through this table of contents okay so is it
easy to find the update statements so somewhere in the table of contents update will be mentioned
with some page number like uh something like let's say uh 567 okay this 567 page you have this update
related topic then what you will do when you find this particular topic and it's
corresponding page number from the table of contents will directly go to that page. So what is the
fastest way guys? Is it to go without the table of contents or going page by page? If table of contents is
there, then accessing this particular topic will become very easy, right? Similar case, similar thing with
the tables and indexes
also. Let's say there is a table. Okay. Let's say there is a table like this. This table has some columns. This
table has some columns. Let's say the table columns are like ID, name, okay? ID, just writing outside
spaces list id name experience and country. Fine? ID name, experience, and country. Now, you got a
requirement. You got a requirement where, I'll move this inside. Okay, so I'll move this inside so that we
have four columns in the table like ID, name, experience, country.
And let's say this particular table has thousands of records. Okay, not one or two or three or four.
Thousands of records are there. Okay, like this thousand records are there. This is the first record and
let's say this is the thousand records are there. Now, what happens here is, let's say there is some UI.
Application UI page is there, web page. For example, here we have Google search. If you go to
[Link] and you will search for something. If I search for QFox, immediately Google will give the kfox
website. Our website. Okay? kfox website. Like this. So, how the google is able to search here this search
box here whatever the uh text you are giving for searching right internally google google will convert
into some query, SQL query kind of statement.
Okay? So, how the internal implementation of Google, we don't know. But here, coming to the same
example, let's say there is a web page like Google. Okay? And let's say there is a text box field like this.
Okay. Beside this text box field, let's say there is a search button. Search button or icon, whatever it is.
Now, this text box field is intended for entering the country. Okay. You can enter any country into this
text box field and click on search. So that what happens is this particular web page will display all the
employed. These are all employee details. Okay. Employee details. four columns are there. ID name,
experience country. If you provide some country here like india or something, okay, all the employees
who are from the india from this employee table will be displayed here like this.
Right? So, let's say here if i specify the country as USA. Sorry. So, let's say Here, in place of the country, I
am providing usa in this text box field and then i clicked on the search box. What will happen internally?
A query will be created. Select, okay, star from this employee table. In the back end, this is a front ui
guys, okay. This is ui part, okay. This is ui part. In the back end, database will be there. DB will be there
having all this employee table and all those stuff, okay. So, whenever, a user goes to this UI goes to this
kind of UI and enters some country like USA and clicks on search what happens is this UI will create a
once you click on search this UI will create a kind of SQL query statement like this select star from
employee table where
where country is equal to, here what country you gave? USA. So, USA will be created. This will be
created by this UI. If you give USA here, this query will have the USA entered. If you give India here,
select star from imply where country is equal to India will be created. And this query will be executed in
the DB. When it got executed on the DB of this particular application, what will happen? All the
employee records which are from the country USA will be filtered from this particular table and
displayed here. This query will run on this particular DB and retrieve all the records of the employees
who are from the country USA and whatever the records we got in the result for this particular query,
they will get displayed on the UI of the page like this.
But here, there are thousands of records. Lot of records are there in this particular employee DB. table
which is at the back end of this particular UI. So anyhow we know that this particular page where we
have to enter only country. We have to enter the country and click on search. Then what we can do here
is to make this. It will take some time to filter the USA records from this employee table and display
here. Some time will be taken by this application to create this query and filter the records who are of
the employees who are from USA and once they get the records, they will be displayed here. Some time
will be taken for displaying this particular employee details who are from the USA from this particular
table by this UI of the application.
But if you want to reduce this particular time the time for returning the records to this particular UI of
the application if you want to reduce the time, some time will be taken here. But if you want to reduce
the time, we can create indexes. Okay. you can create index for this employee table. So, yes, I will be
creating some index for this employee table. That's all good because i am trying to retrieve some
records from very good number of records but here here i am entering USA. USA is a country. Country is
one of the column in the employee table. So, here index will be created for not the complete table guys.
Okay. Here index will not be created for not for the complete table.
We have to create index for this employee table for only country column. Okay? Because we are
searching for with the country name. Okay? And you need to, if you create an index with the country
column, okay, the table of contents like different countries, okay, table of contents kind of thing like this
with different countries, India, USA, UK, Spain, like that all the countries will be, table of contents will be
created in this particular index internally. Okay? We will not see this happening. If you create an index
for the employee table for this particular country column, this kind of table of contents based on the
country column will be created. Now, whenever you search for this USA, then what happens internally
is, so with the help of this index, we will be able to retrieve all the records of the employees who are
from the country USA or specified country in a faster manner, similar to the table of contents of this
book.
So, without table of contents, you have to go through first record if the if the usa is not there in the first
record, then second record. If the usa is there in second record, okay, retrieve this. Again, third record. If
USA is not there here, again, fourth record. Like that, we have to completely filtering one two thousand.
Okay? We have to keep on going from first record to thousand records. But if you create some kind of
index like this, okay, where exactly this usa country records are there, okay, internally, it will create this
kind of index. So, if you create an index for this employee table for this country column, whenever you
search for this USA, the retrieval process will become very faster.
Okay. Here, time will be reduced. Retrieval. Okay. The time taken for retrieving the records of the
employee table who are from the country USA will take less time. After using index, it will take less time.
Because of the index, the retrieval process becomes faster. But one more thing you need to understand
here, guys. Okay. Don't create index. unnecessarily okay if if it is this kind of requirement where you
have a page where you have to enter the country and search and get the details from the employee
table. Okay. Then only create the index for this us country kind of column. Okay. You can create for the
index for the employee table for this country column. But unnecessarily if you create the index what
happens is your insertion and updation operations will become slow.
Okay. Will become So, if your requirement is to only retrieve the records from the tables, then feel free
to create index for such kind of columns in that particular table. But, if you are mostly relying on
insertion and updation to this particular table, then our indexes does Indexes, by creating the indexes,
this process like insertion and updation uh statements of sql will be will make the process very slow.
Okay? If your intention is to insert some records into the table or regularly or updating the table
regularly, then indexes should not be applied on the table. Only if you want to retrieve the records from
the table every time, then only we have to use the indexes, okay? Indexes will make the retrieval faster,
but insertion and updation slower.
Okay. It's possible but you better to create indexes for the required required columns that you want to
retrieve based on. Okay. The condition. Fine. So let me explain. So things will be more clear for you soon
guys. Okay. So whatever the examples i gave here and all those things will become more practical and
more relevant for you now. So what i'm trying to do here is uh Here, as you can see in the MySQL
workbench, there are four DBs being displayed. This QFox DB is created by me in one of the previous
videos. And this Satellite Assist and World databases came by default with the MySQL. I have not
created them. They came by default. But coming to QFox, I created. So I'm going to use the QFox table in
this video session just to demonstrate this index as concept.
Fine. So how to select the database QFox? I would say use QFox. Run this. Now QFox database got
selected. Now I can work on any of these tables under this QFox or create any tables under this QFox
and I can perform different operations under this QFox because I selected the QFox database now. Now
there are few existing tables guys. What I will do is I will just drop them. I don't want them. Drop three
tables. I'm just clearing out the earlier stuff, whatever I created. So here tables are there. Okay. There
are no extensions and all the stuff. That's fine. Now, what i'm going to do is i'm going to create this table.
Okay. This employee table i'm going to create. I, with the ID, name, experience and country columns i
am creating some data guys before i am creating some index for this particular table, I have to first
create the table itself, right?
So, for that i am going to create a table create table emp1 id int name where care square care let's say
15. Then, here some spelling mistake in the data type so where care and experience, again int. After
experience, again what is their country right country column country where care again 15. So, I just
created this create table statement with four columns in this emp1 table. First column name is id, then
we have name, then experience and country. so with these four columns i am trying to create a table.
Now, as you can see, the table got created. If you refresh here, the table will fall here. EMP1 table. If you
expand this, there are four columns in this table. That is id column, name column, experience column,
and country column and uh are there any index for this particular table?
You see under indexes, there are nothing is there. Okay. You have a statement guys, SQL statement to
see whether there are any indexes created for the emp1 table. So, show indexes, show indexes from
EMP1. I have to say like this. Show indexes from EMP1. If I run this, you see, there are no indexes, zero
indexes. It's blank. Okay. Indexes are not there. And are there any records in this particular emp1 table?
It will not be there because this is just now created, right? We have just now created this EMP1. if you
want to confirm that, select star from EMP1. If I run this, you see, there are no records. And even
indexes are not created for this particular mp1 table. In order to find out if there are any existing indexes
for this emp1 table, you have to say, show indexes from table name.
That is emp1 okay now now i am going to insert some records into this particular table, guys. Okay? This
table is kind of empty. As you can see, select star from emp1 is resulting in empty table having only
these column names like ID, name, experience, and country, right? So now let me create, insert some
records into this emp1 team Select, star, sorry, I am saying select, insert, okay? Insert into emp1 values,
one Arun, 2L, experience is 2l and country is uh i am saying India, okay? India. Then we have insert into,
EMP1 values 2, Tarun 7 experience and USA. Okay. USA. Third thing. Insert into EMP1 values 3, Varun 9
years of experience and then he is from let us say UK. Like this I created
I am trying to insert three records into this EMP1 table. Run this. So three records got inserted. Now say
select star from EMP1 and you will get the table ID that is EMP1 table with the columns ID, name,
experience, country and under those columns we have three records. First record, second record, third
record with all the details I have provided for insertion. Now good. Now guys, tomorrow there came a
requirement where I need to retrieve the employee details from this emp1 table, who is from the
country USA? Okay. I want to get the details of the employees from this emp1 table who are from USA.
So how to do that? I will write a statement like this, right? Sorry. Select star from emp1 table.
Get all the records from the emp1 table of the employees. Okay. Who are from which country their
country is equal to usa i have to say like this is a statement i have to write this when i run this what will
happen instead of retrieving all the records from the emp1 table okay only the records of the employees
who are from the country usa will be retrieved so here before i run this particular statement as you can
see there are three records and only one person that is second person is from around is from usa so if i
run this the result will be the wrong guys okay run it fine so like this now what is the condition in the
where class?
Country. This is the condition we are using for retrieving the records from the emp1 table. Right? So, if
you are using the same condition every time, it's better to create an index for this particular emp1 table.
Okay? For the column country. Because it will increase the performance and increase the, improve the
performance and increase the speed in which the records can be retrieved from this particular table.
That's the reason we have to use this. Here I explained, right? There is a front-end application where you
have to enter the country and click on search. In the background, select star from employee where
country is called US will be created. And this will retrieve the records from employee table. Let's say
there are thousands of records.
It will become very difficult. It will take a lot of time. Now, if you create some index based on this
country column, this time will be reduced. It will become faster. Retrieval process will become faster.
Same thing here, guys. So, here country is called US. This is the search term. This is the search term we
are using for getting the records from this EMT1 table. So if you create index for this particular search
term column, then the retrieval process will become fast. In this example, there are only three records.
In real-time applications, there will be thousands of records, lakhs of records. In that kind of cases, if you
simply use like this without creating the index for this particular EMT1 table, what will happen?
It will take a lot of time. In order to increase the performance of the application or to increase the speed
which the application has to retrieve the records from this EMT1 table, we have to create the index for
this particular table for that particular search column that is country. Okay? Now, this is working fine,
but you know to increase this speed in real time, here i cannot show you the speed guys, okay? Slow
speed and fast speed. Okay? I cannot show you the recording performance, but just understand the
concept why we have to use indexes. They will increase the performance or the speed at which the
records will be retrieved from the table. Okay? But here i am going to give this example just to show you
how to
write the syntaxes for creating the indexes, okay? Finding out whether there are any index existing
indexes in the table, etc etc okay? That you are learning here. But in real time, this situation, the
developers have to create the indexes for the cmp1 table before, okay, using this query for retrieving
the records from the employee table who are from the country US, okay? For the country column of the
employee, they will create the index. Now, let me create an index. Till now, I have not created an index,
right? and if i say show indexes from EMP1, it will be empty. Indexes are empty. But if i create an index
for this particular country column of this emp1 table, what will happen let's see create create index okay
index name country country index okay country index create index country index okay uh on on create
index country index on
I have to give the table name guys, okay? On, I have to give the table name like this, okay? On table
name. So, on what is the table name? Table name is EMP1. EMP1. The column is, the column is, which
column, for which column I have to create this index? Create index. This is the name of the index I am
creating guys, okay? Because I am creating an index for the country column of the EMP1 table, I just
gave the name like country index. You can give any name here. Okay. CI also you can give. You want to
give CI, you can give that. Okay. To make it readable, I'm just giving country index. Okay. Create index
with the name country index or any other name on EMP1 table for which column?
For country column. You have to give that a column named here. Okay. Here, this particular EMP1 table
has country column. So, I'm going to retrieve the records from this EMP1 table using this country is
equal to USA in the condition where class condition. That's why I'm making the country as an index.
Okay. So, I am choosing the country column for the creation of the index. Create index country index on
EMP1 table for which column country column. If I run this, an index will be created. You see the index
got created. Now, if I say show indexes from EMP1. Okay. Show indexes from EMP1. Earlier, there were
no indexes for this EMP1 table. But now, for the table EMP1, a index got created. Okay.
And for the column, which column country column it got created. The name of the index is country
index. Okay. Index got created guys. So, what is the benefit of creating the indexes? Now, tomorrow if I
say select star from EMP1 where country is equal to USA. Okay. We will get the results but bit faster
than without indexing. Okay. Without indexing of the table, we will also get the results. But the time
retrieval time for retrieving the records from that particular table will be slower when compared to the
tables which have the index created like this. Okay. Here also when you refresh here, for this emp1
table, under the tables, we have only one table that is emp1 table.
Expand this. Here we have columns.
These are the four column Now, earlier, we don't have indexes here. Now, we got the country index
created okay you can see the under the tables itself you can see the for the particular column, under the
indexes we will find the index names. Okay? Whatever the indexes you create here, they will be
displayed here, guys. Okay? Or you can run this statement, show indexes for, from EMP1, that will
display the indexes that are created for this particular table. Fine? now is now you understood what the
purpose of the indexes and why we have to create indexes for the table columns okay all those things
you have understood clearly now the next thing is for few things you don't have to create indexes for
example uh i'll explain for example you have a particular table and it has some columns and this
particular column is specified with primary key then index will be automatically created for that
particular column guys okay i'm going to show you i'm going to show you with that example
so for that, what i am going to do is i am just trying to uh create another table okay create table emp2
table okay mp2 id int here i am giving this as primary key. And name as var cap 15. Like this i am giving
this table while creating this table, for one of the column, this primary key is specified so i am not going
to create any index for this id column. But automatically, okay. If you have a table, if you are creating a
table, and if you are specifying this primary key for one of the columns while creating the table, then
index will be automatically created for this primary key column. Okay? I'll show you. So, let me first
create a table.
Run this. When I create a table, table got created, guys. Refresh here so that you can see the table
created. EMP2 table is there. Now, I have not created any index manually for this ID column or this
primary key. That is nothing but ID column, right? Primary key is there for this ID column. so i have not
created any index for this id column of this primary key. So, but still, even though i didn't create any
index for this particular column, uh, that is primary key. Then if i expand this, so there are two columns
like id and the name and under indexes, if you expand, there is some index coming guys primary. Okay.
This is coming because for this particular column guys.
Okay. So for the columns which are specified with primary key, you don't have to create indexes indexes
will be index will be created automatically. Okay, primary index will be created automatically for this
particular column. Similarly, one more example let me give. That is, not only primary key guys, if i specify
this particular column with unique, unique, okay, integrity constraint, then also the same thing will
happen. Okay, then also the same thing will happen. If I say create table, emp3, id, int, unique. Okay, so
for this particular column, if unique is specified, you don't have to create index. Okay. Automatically the
index will be created for the column. Okay. ID column. So you can see that in action just now. If I say 15.
So in the emp3 table i am create i am trying to create two tables. One of the table is specified with
unique. Okay. Unique. So what happens is when i create this, automatically index will be created for the
id column. Okay. Run this. Refresh here. EMP3 table got created. Then expand this. Columns are id and
name. but index is ID index. Okay. Index is created for ID guys. So you can even say show indexes, show
indexes from table name is EMP3. Okay. If there are any indexes for this table name, it will be displayed.
So EMP3 table has an index for which column ID column. Okay. For which column ID column. Key name
is ID automatically created. Okay. Because this is specified as unique.
That's the reason it's getting created. Okay. so if you specify any column with unique then automatically
index will be created for that particular column so guys this is all about this is all about indexes and how
to use them in sql statements and their purpose for increasing or improving the performance of the
application while retrieving the records from the respective tables table columns so that's it guys see
you in the next video session thank you bye
hello everyone welcome to part 84 of SQL for beginner series. In this video session, I'm going to explain
about JDBC. As part of explaining this JDBC concept, I'll be showing you how to connect to a MySQL
database from the Java programs. So in this video session, I'm going to explain about JDBC.
As part of explaining this JDBC concept, I'm going to practically show you how to Okay. Connect.
Connecting to a MySQL database from the Java programs. Let's say there will be some Java programs
here. Let's say this is Java code. So this is a piece of code. Let's say these are Java code lines. Assume
that these are the lines of code of Java. From this Java code, using this Java code, we are going to
connect to a MySQL DB. Okay. mysql DB, we are going to connect, okay? So how to do that? How to
write a java program in such a way that you can connect to the mysql DB, okay? This connection should
happen from the java programs to this particular mysql DB.
And as part of this connection, you can perform different after connecting to this database from the java
programs. These are java programs, guys. Let's say this is a java program. And when you run this Java
program, you're going to connect to this MySQL DB. When this Java program is executed or run, you will
get connected to the MySQL DB. And thereafter, you can perform different operations on this DB like
executing some SQL statements and reading the data from the tables and a lot of things. Whatever the
things that you can perform on the DB, table details, all those things you can perform here. I'm going to
show you practically how you can achieve this kind of thing.
Fine. but guys, this is the predict side for this session.
Okay? There is a predict side for this session in order to in order to okay in order to do this thing, what
we need, we need to have basic java programming. Okay? Without having the knowledge of the java
programming, this may look a bit difficult for you. Okay? This explanation that i am going to do now may
look difficult because If you have some Java programming knowledge, you don't have to worry, guys.
You will understand the complete session. And whatever I'm explaining, you will clearly understand. But
if you don't have the basic Java programming knowledge, then it may become difficult for you to
understand each and everything that I'm going to explain in this session. Rather, even though, guys, just
for your knowledge, even though you don't have this basic Java programming, try to focus as much as
you can.
on the concept I'm explaining by taking this Java programming as a means, fine? So even though you
don't understand whatever the Java code that I'm going to write in this programming, I mean this video
session, so try to focus more on the concept,
okay? Try to focus more on the concept rather than the programming if you don't have the basic Java
programming knowledge. But if you have basic Java programming knowledge, you will clearly
understand this current video session, fine? that is one thing guys, you have to keep in mind. So now, so
now the next thing is, next thing is all about JDBC. What is JDBC and all the stuff, okay? So let me
explain. So here, in the previous videos, okay? The current video is 84 they have have explained I have
explained about SQL for beginners.
From the first video to the 83 videos so far, right? This is the 84th video. In the previous videos I
covered, okay, what I did? I connected to the database. Which database I mainly used? I connected to a
MySQL DB, okay? I connected to the MySQL databases, you can say. For example, this is a MySQL
workbench, right? This is the client. So here, there are four DBs. This is created by me in one of the
previous videos. This came by default when I installed MySQL in my machine. The circular assist I wrote
came by default when I installed MySQL in my machine. But coming to QFox, it was there from long, I
mean, this was created by me in one of the previous videos.
Whereas this came by, these three other three came by default when I installed this MySQL in my
machine. Fine. So here, what is QFox? QFox is one of the database of the MySQL. and what is Sakila?
Sakila is also one of the database of the MySQL. this is also one of the database of mysql and world is
also another database of the MySQL. So, in order to connect to this qfs database or circular database or
sys database or world database, what i am using? I am using this mysql workbench it acts as a client yes
okay a client it's actually as a client and uh server is there uh from the client, we can run the queries and
this queries will trigger the server all these things i already explained as part of the previous videos,
right?
Now, so in order to connect to this my one of the mysql databases, so far i have used what? Till the
previous videos i have used mysql workbench client, right? Let me show you how i connected, okay?
How I connected to this one of the mysql db using the mysql workbench client, let me show you. If I
close this, And, again, launch this, guys. How to launch? If I search for Workbench, since mysql is already
installed in my machine as part of the previous videos i explained, you will get this option. Just click on
that. It will take a while uh to launch. Once it got launched, what i have to do, I just select this option,
right? Now, it is asking me to connect to the mysql server.
When I give root here, okay, as a password, which i have sent in as part of the previous videos, when i
click on OK, now, When I connect to the MySQL server, automatically all the databases in the MySQL
server, this MySQL server are displayed here. There are four databases currently in the MySQL server.
This was created by me in one of the previous videos. Other came by default with the MySQL server
when I installed in my machine. So how I connected to these databases now? With the help of MySQL
workbench, I am able to connect to this. There are four databases which are there in the MySQL server.
Fine. But But guys, this is good. What if I want to connect to the MySQL?
One of the MySQL DB. One of the MySQL means it can be any of this. It can be QFox DB or it can be
Circular DB, it can be SysDB or it can be VoltB. If I want to connect any of these DBs, which belong to the
MySQL server, that's why I'm calling MySQL DB. If I have to connect to any of the MySQL DBs, from the
java programs okay java from the java programs, I would like to connect to this mysql DB. What I have to
do? Okay? Earlier, in order to connect to a mysql DB, what i have used i have used mysql workbench
okay a ui kind of client from which we can connect to the MySQL database and we can run the queries
on the MySQL database.
All these things I already explained as per the previous videos. But now what I want is I would like to
connect to this MySQL DB without Workbench. I want to connect via the Java programs. From the Java
programs, I would like to connect to the MySQL DB. Is this possible or not? This is possible or not. Yes,
guys, it is possible. We can even connect to the MySQL, one of the MySQL DBs from the Java programs.
And this concept is known as JDBC. Okay. The concept of connecting to the databases from the Java
programs is known as JDBC. JDBC stands for Java Database Connectivity. If you are connecting from the
Java programming language, then we can call it as JDBC. So other programming languages also we can
connect to the DBs.
They have different names. Here, if you are connecting from Java programs, it is called JDBC. But other
Java program, other programs like Python or some other things may have some other names. Okay. It
may not be JDBC like that. So JDBC is a concept where if you want to connect to the MySQL, one of the
MySQL DB from the Java programs, we call it as JDBC. Full form of JDBC is Java Database Connectivity.
Okay. Java. Full form of JDBC. JDBC stands for Java Database Connectivity, guys. Connectivity. Okay, fine.
This is the full form of JDBC.
Now, in this video session,I am going to practically show you everything, guys, how to connect to a
database from the Java programs I am going to show you.
But as explained earlier, you need some basic Java programming to understand each and every concept
of this session in a detailed way. But if you don't have any Java programming knowledge, at least try to
understand the concept that I am going to explain as part of this session, okay? you need to learn Java,
guys. Otherwise, you will not understand this session okay java is a pretty set only for this particular
video in my course fine so now guys uh how to connect to mysql database from java programs? Here I
am saying and i will be able to connect to the mysql database from the java programs, which i am calling
it as JDBC. But how to do it practically? Let me practically show you.
So, in order to get started with we need few softwares. installed in our machine. Okay. We need to
install some software in our machine. Then only we can do that first is we have to install Java. Okay. We
need some predict sides. We need to, because we have tried java programs, right? Without writing java
programs, we cannot connect to MySQL. In order to write the java programs, we need two software like
Java, Java software, Java SDK. Okay. Other one is eclipse ID. These two softwares we need. Java SDK is
without this software, you cannot write the java programs, guys, okay? It has libraries and everything for
java programming related stuff, okay? Without Java SDK, we cannot write the java programs. And we
need some tool, right?
For example, here, if i have to write a document, I will open the notepad, okay? So, hi, how are you? I
am writing something here. Assume that this particular thing is Java, okay? Assume that this particular
text is Java, Java code, programming code, okay? And the place where you are writing is a notepad,
right? so here notepad is the editor. Notepad is the editor and this is a java program fine in order to
write this java program in my machine i should have the java java sdk software installed and in order to
write this in order to write the in order to write somewhere okay we need some editor, right? This
editor we need, okay? This editor we need. So that editor for java programs is eclipse IDE, okay?
There are many editors guys, Eclipse IDE, IntelliJ, like that many editors are there. So most of the people
will be using Eclipse IDE. So it's very easy to start and get started and a lot of community users. So I'm
choosing the Eclipse IDE as editor for this Java programming. So here without Java SDK, we cannot write
the Java programs. And without Eclipse IDE, we don't know where to write. Without Eclipse IDE, Eclipse
IDE is the editor. Without editor, we don't know where to write even though we have Java. if you don't
know where to write there is a problem, right? This is the editor and this is the software for writing, for
getting the java programs written. Fine? So guys, we need these two softwares.
So let me practically demonstrate how to install java followed by how to install eclipse id okay? For this
particular video session. So first of all, let's install java SDK. Go to any browser, let's say google chrome
browser and search for java sdk 8 download, okay? I preferably use 8, guys. So it's a kind of a stable
version and it's a different story, guys. So I don't want to explain here. It has a long-term support. Simple
speaking, Java 8 has a long-term support so far. So we are waiting for another version of long-term
support version of Java. Anyhow, don't worry too much about that long-term support and all. Just simply
search for Java SDK 8 download for now.
So when you search for that,
you'll get this first link like from [Link] saying, Java SE development KTI, click on this. And you click
on this, it will take you to a different page like Java SE development KTI downloads. Scroll down, scroll
down. Here there are two sections, section one and section two like this. Just go with the section one
guys, this is enough. Go with the section one, this is enough. And under section one, there are different
operating systems being displayed here, Linux. But my machine is like Windows machine guys, okay?
windows 10 machine so i will go to the windows machine and that to my machine is a 64-bit machine so
i will go i will better choose windows x64 okay i'll choose better windows x64 uh 64-bit version of the
windows uh for windows uh for java software okay this is a java software guys which is for windows 64-
bit okay purpose so click on this
It's asking like to agree something and just I review and accept the Oracle network license agreement.
Okay, so then now what I'm going
to do is I'm clicking on download JDK. Okay, just click on this download JDK. So it will take you to the
Oracle sign in page. Okay, already I created an account with this [Link]. Okay, oracle
[Link]. I already created an account. If you don't have an account, just create this account
from here using the create account button, then you can download. uh since i already have the account
created with this Oracle, so i'm going to directly provide my credentials, okay? Username and password
i'm going to provide. Like this, I need to provide and click on the sign in. Then what happens is, so it will
download, okay?
Java JDK, that is java sd jdk will be downloaded. for windows 64 bit, but the problem is it will take some
time guys so since i already downloaded in my machine, okay so since this is already there, I don't want
to download again. I'm just cancelling it. okay so like this, you have to download guys once you
download you will get this file in your downloads folder. Double click on that file. Now. just click on this
uh i got a kind of user access control in my machine uh if you are able to see, that's fine. Otherwise, just
click on this if you get it. So, it will launch the installer, guys. Java installer will start in a while. Let's wait
for the installer to start.
You should get an installation wizard from java sdk8 okay jdk8 so it's loading. Yeah, we got it. Okay. So
this kind of installation wizard will come when you double click on this uh downloaded file click on next
preparing to install now okay so again click on next just keep clicking on next guys. So the progress uh it
will take a while guys. These installations will take a while. I would like to explain everything in detail. So
I'm just trying to cover the installation part also. Okay. So as it is taking too much time, I will pass my
video guys. Once the progress is, uh, reached to a particular point, I will again resume the video
recording. Okay. Okay. I have resumed the video guys, uh, because as it had, as the status has reached
till the end, I thought like, uh, resuming it again.
So let's wait for it to complete the status now. Almost there. so it's removing files, copying new files.
Let's wait for it to complete. So if you have java installed, already installed your machine, you don't have
to do these guys. But if you don't have Java, then you have to go with this process. Okay. so almost there
i'm going to pass the videos and record i mean resume the videos guys just with an intention of saving
your time okay in real time it may take more time okay so some of the things may take more time just
i'm trying to pass and resume the videos just to make sure that time is not wasted for you now we got a
destination folder dialog where
this is the place where the java will be installed in your machine. See program files, Java, this particular
place. Click on next. I don't want to change anything. Now it started installing the Java. So, it's almost
reached till the end. Let's wait for it to complete this installation part. Okay, now we got this uh
complete java like sc development kit, okay, that is sdk hit sdk got, SDK, yeah, it got successfully installed
and i just need to close it uh now java is installed in my machine, guys, okay? So first step is done. What
is the first step? I have to install the java software. Then only i can create the java programs using that
software. Next thing is that i need an editor, okay, where i can write the java programs, okay?
I need an editor where i can run the job programs. but editor i'm going to use it as eclipse id in this case.
So from where to download this eclipse id Again, go to [Link] and google search for google search
for eclipse id download
okay simply search for eclipse id download you'll get this link. That is [Link] downloads. Click on
this. And you will get to this downloads page. And here we have get eclipse id some version and
download. Uh, this is the latest version guys, whatever that is being shown here is the latest version so i
am going to click on this uh download 64-bit okay download 64-bit click on this. So again, we are taken
to another page where i have to again, click on the download i will again click on the download.
So the download has started, right? The download eclipse id download has started. already downloaded
guys you don't have to, okay? So, I already have this uh in my downloads folder. So, this thing. You can
either download or, okay? I'm just cancelling because i already have this uh downloaded already. So, just
double click on this uh downloaded thing of eclipse for windows 64. So, it will also launch some kind of
wizard kind of thing will come, guys, again. Okay? Similar to java will get a kind of wizard. This kind of
installer will come. Installation wizard. Okay, it's going to launch the installation wizard. Let's wait for it.
Fine. So guys, installations are very important. Okay, so we have to configure and install everything like
java and eclipse id editor for this.
So I am trying to show you in a detailed manner. I don't want to skip anything. Fine, it's launching almost
there. Eclipse installer is launching. It's loading now. After launching, it is loading. So it has to display few
options here. Let's wait for the options to be displayed in Eclipse ID installer for us to select. So, just
displaying anything. Let's see. Okay, we got it. As you can see here, there are different options there.
And here, Eclipse ID for Java developers is there. Eclipse ID for enterprise Java developers are there. So,
Just make sure that you select the second option, Eclipse IDE for enterprise Java developers
for this need. So we need to have this option. So don't select Java developers. There is some problem in
this.
If you do this so, you'll get the same thing, but we'll not be able to solve something in this video session.
So better to take this Eclipse IDE for enterprise Java developers. Select this. It's asking you to whether to
install or not. Okay. So I am selecting enterprise guys. Keep in mind that you have to select the
enterprise version of the Eclipse IDE. Okay. For Java developers. So click on this install guys. It will take a
while again. So to install completely, let's wait for it to completely install. So it's a bit fast than I thought.
Let's wait then. So... It's almost there. It's almost there till 75%. So only 25% progress is left. Let's see
whether it can install in less time or not.
Okay. So the installation has been completed here and we need to simply click on launch. Okay. Once
the installation is done, you'll get this launch option. Just click on the launch. Now Eclipse ID will be
launching. So our editor where we have to write our Java programs. is launching guys. Okay. This is the
editor in which we are going to write the java programs. Now both the predict sites will be satisfied.
That is uh installation of the Java, uh, like uh jdk and then uh then eclipse id for java enterprise
developer. These two softwares we have installed already. Now we have to simply follow all these
practical steps. Okay. To understand how to connect to the, my, one of the mysql database, from the
java programs, okay?
That's the concept. For that, we need to follow the below steps. So, I'll explain you, okay? In a step-by-
step manner explain you. So, like, once the eclipse side is launching, it's uh asking you whether this is
the place where you want to store the eclipse ide projects what are the projects that you are going to
create, Java projects, you are going to create in this eclipse IDE, will this place will be good or not, okay?
In the c drive under users, under arundium folder uh under eclipse workspace, it's going to create the
projects okay whatever the java projects i am going to create, they will be stored in this particular
location. Click on the launch. Eclipse ID is launching. So let it launch.
So meanwhile, what we can do is like, we need one thing guys. Okay. Before I explain you. Okay. Before I
explain you how to create Java programs and from Java programs how to connect to the MySQL
database, we need some test data. We need some data that should be there in one of the DB of this
MySQL. So let's say I'll switch to the MySQL workbench using which we can connect to the database that
is MySQL server already, all the database in the MySQL server. What I will do is I will create a table guys.
I need a table. In order to explain this Java program and connecting to the JDBC, I need something. So I
have to do something here. I will come to that.
Looks like the Eclipse IDE has been launched. Simply close this welcome and just keep it like that. So
don't do anything guys. Just keep it like this. We are going to do something in Eclipse IDE. So before that,
in the MySQL workbench, we need to create a table in one of the databases here. So, I would like to
select this QFox database which is created as one of the previous videos. I would like to create a table
under this QFox. Out of these four databases, I have to select this QFox database from the MySQL
workbench. Use QFox, I am saying. Run this. This database got selected. Now, I can create tables, I can
delete tables, I can do anything under the QFox database.
After selecting the database, you can do anything here. So expand this. Already there is one table here.
I'm going to drop it. I'm deleting or dropping it. So that table will be deleted or dropped completely.
Fine. Now I want to create a new table. Okay. So this is for my testing purpose. Okay. I need a database
QFox. Under that I need a table already there in the database. Now from this Java program that I'm
going to write in this particular Eclipse IDE editor,
I am going to connect to this particular database. Okay. Database table. Okay. I'm going to connect to
this database and perform some operations on this existing table. That's my future thing. So, in order to
write the Java program and then connect to this particular QFox DB and perform some operations on
one of the table under this QFox, I need a table, right?
So, let me create the table from the MySQL workbench, okay? Using the MySQL workbench client, I will
connect to the MySQL server and create a table under this QFox database, okay? So, how to create?
Create table. table name okay create table table name id column names i am giving. ID as int. Only two
columns. Name as varchar varchar 15 okay this is the table. EMP1. In the two columns are there id and
name. Okay. Two columns i am creating. Run this. So once you create that, if you say select star from
EMP1. Okay. Star from emp1 table name. Okay. So, we will get an empty table. Only columns will be
there. No records will be there. Let me insert some records. For sample, let me insert 3 records, guys.
Insert into EMP1 values as 1, Arun. Second record as insert into EMP1 values as 2, Arun. Insert into
EMP1 values as 3, Arun. Like this, sum 3. records I'm trying to insert into this EMP1 table, run this at a
time so that all the three records will be inserted at a go. Now select star from EMP1, you'll get the table
with three records.
Now we have the table, whatever the table we want, right? In this QFox database, we have already
there, okay? This database is already there and under that, this EMP1 table having this different records
is already there. Now, the next task for us is, okay? I have to create some Java program in this Eclipse
IDE. Okay. In this Eclipse IDE editor, I have to write some Java programs.
And from that Java programs, I need to connect to this particular QFox database. After connecting to
this QFox database, I need to perform some operations on this EMP1 table. Okay. That's the plan, future
plan, guys. Okay. So keep that in mind. Not to write the Java programs here. We need to create a Java
project. Okay. I will create a Java project here. not not normal java project, but i will go to this project
option, guys, new project. And here, instead of selecting the normal java project, I will select this maven
maven project maven java project i am going to create.
Click on next. So, you should also have some basic knowledge of Maven, guys, okay, to understand this,
okay. So, without having an understanding of java programs or java basic knowledge or maven basic
knowledge,
This session may not be completely understandable, but you can still try your level based in
understanding. Okay. The concept of JDBC. Fine. Fine. Next thing is here. I need to click on next. Okay.
So without, you should not select this option guys. Okay. Create a simple project option. You should not
select and directly click on next. And you got a kind of all catalogs. By default, you're not seeing
anything. So what you can do is you just try to select some other options. Okay. Like this, keep on
selecting and then again, change it back to the all catalogs. Okay. all cat. We should get a lot of uh
options here. Okay. Maven central is not coming. Default local is not coming. Internal is coming, but uh
yeah this will be good.
Internal is good. Okay. Just select this internal. This will be enough. And in this internal here, you just
filter for maven archetype. Quick start. Okay. This is what we want. Maven hyphen archetype. Quick
start uh archetype in the maven project we need to select this this option you just select okay then click
on next
okay make sure that you select the same artifact i mean maven archetype quick start only don't select
other type guys okay you will get a different template of java project okay we need this kind of template
click on next quick start template we need now here just provide the project name say demo and some
package name like a pack okay some demo and pack i'm just giving guys normal names click on finish
so here maven project is giving maven java project is getting created guys uh we have to wait for it to
complete the hundred percent here okay let's we have to wait uh we should not touch this or uh we
don't uh if you want to get the complete structure, you need to wait for the hundred percent of this
progress. okay then only you'll get the complete structure of this uh maven java project. So it's still 77
we have to wait for the hundred percent to be completed.
So let's wait. once the maven java project is created, we are going to go to the next step, okay? Now,
looks like it's completed, guys. As you can see, the status has been disappeared from here.
And this is a maven java project, okay? Maven Java project, mj okay? Maven Java project. Expand this.
And expand these two things. You see, we gave the project name
as demo and package name as group package name is pack, okay? So, it's creating pack dot demo
packages so we don't need these things guys. Just delete this [Link] or uh okay rightly select delete
option and uh even you don't need this app [Link] also we need to delete that too. Okay, I'll show you
how to delete that. So let's wait for it to complete uh deletion of this. So now let's delete this. Right click
and delete. Now it's done. So, what next is, the next thing is after deleting this stuff, you need to, we
need to download a MySQL, okay?
The first thing here is Java SDK, XFID and third thing is we need to, okay? We need to create a Maven
Java project. This is the third step. We have created the Maven Java project, right? After creating the
Maven Java project, what we have to do? We have to download, okay? We have to download. mysql
java connector, okay? MySQL Java connector kind of thing we need to download. So in order to
download, Maven will make your job easy, guys. Since we have this maven tower project here the the
simple way of downloading this mysql java connector
is to open this [Link] file, okay? Just keep it, okay? Just keep opening this uh okay this [Link] file
should be opened here. And here, you can see,
dependencies starting here, dependencies ending here, and inside the dependency stack, we have the
dependency, slash dependency. One of the dependencies is here. We need to add one more
dependency here, okay? That dependency for this MySQL Java connector. How to get the dependency
for that? Here, dependency is there for the JUnit, but we need another dependency which need to be
added under this dependency stacks, okay? That dependency should belong to the MySQL Java
connector, okay? So for that, here, I'll go here. I'll search for mvn repository. Okay. Search for mvn
repository.
You will get this mvn [Link]. Click on this guys. Click on this. Uh, here we have been taken to
the mvn [Link]. So here we need to search for MySQL, MySQL Java connector.
Okay. Just search for this mysql java connector and you will get this mysql java connector. Okay.
Connector Java from for MySQL. Just click on this. and then just select the latest version, whatever that
is possible. 8.0.20 is there. Just click on that. And here maven is there. Under Maven, this code is there.
Dependency code is there copy this okay this is this is something related to mysql connector Java, okay?
We need to copy this. Copy this and again come to your eclipse IDE. Here, along with the junit
dependency, you just need to add mysql connector Java, okay? MySQL connector java you need to add.
and after adding this to your [Link] file of this maven java project, just click on save all. So here,
downloading of that particular mysql connector java driver,
okay?We'll start. MySQL connector java driver will be downloaded, guys. This is a driver, guys. MySQL
connector java is a driver. So it got downloaded, guys. Progress has been completed. Where you can see
that now after downloading? Here when you add dependency tag and you click on save all button, it got
downloaded. But way to find the downloaded file? So, under maven dependencies,
it will be displayed. Expand this maven dependencies. You can see that mysql connector Java, okay, jar
file, driver jar file got downloaded here. Okay. So, this is how we have to download the mysql java
connector. Okay. MySQL Java connector need to be downloaded. What's next? So, we have downloaded
the mysql java connector connectivity driver. Okay. Java connectivity driver is done.
Now, next thing is we have done with, we are done with all the, you can close this [Link] file. Okay.
Now, the next thing is, next thing is we have tried the Java program guys. Okay. We have all the setup
done. We have, we have downloaded and installed the Java 8 SDK, JDK. Okay. So, then Eclipse, we have
installed Eclipse IDE editor. then we have created a maven project, Java project under under this eclipse
id editor. And then we have downloaded this mysql java connected driver. Okay. All these things when
you are done. Now you can start writing your java program. Okay. So under src test Java, under this pack
dot demo right click on this pack dot demo and say new guys.
But along with that, select this checkbox option, public static voidment, checkbox option, click on finish.
So some other code will also get generated here. Fine, now we have this demo class, under that we have
the main method. Inside this, we have to write the java programs. So first line that i have to write is, for
what i am going to write here is i am going to write for connecting to the database. Which database?
Here, as you can see, Here I have used MySQL workbench client for connecting to this databases. QFox
database I connected, circular database I connected, sysworld database I connected. How it is possible
with help of MySQL workbench client? Here I would like to do the same thing with the help of the Java
programs.
I would like to connect to one of the databases of this MySQL server. Let's say I would like to connect to
this QFox database. How to do that? For that we have something known as driver. manager class. Okay.
Say driver manager. Say dot. Then get driver manager dot get connection. Here you need to select three
parameter option. Okay. So get connection of string string string. Okay. This thing. This thing you need
to select guys. When you select this. Okay. Like this it will come. Driver manager dot uh get action. Here
So, this driver manager has come from [Link] driver manager
okay so from java from java libraries we got this driver manager. That's fine. Driver manager dot get
connection. So, here i need to provide the URL.
Okay. First, I need to provide the URL. How to provide the URL? JDBC colon. What is the database name?
MySQL. Okay. MySQL. I mean, MySQL is a server name. Database server name is MySQL. JDBC is a
concept. JDBC colon MySQL server name. Then colon. Then say double slash. Then say local host. Local
host. Why I am saying local host? In my machine, this particular MySQL server is installed. I would like to
connect to this MySQL server. via jdbc that is Java. From Java programs, I would like to connect to this
mysql server. And this mysql server is then my local host. At which port this mysql server is running. So
for that, I can show you something, guys. Okay, I will close this mysql workbench.
And if i open this workbench again, if i open this workbench again, let it open, guys. MySQL workbench,
let it open. So welcome to mysql workbench client. Here, click on this. You see here, all the details are
there mysql workbench and mysql server is running in the my local machine, in my machine if it is
running in another machine you will get an ip address here of that particular machine guys okay if you
don't have the ip address if it is running you know same machine, then you will get the local host, okay?
Then in which port number it is running double three zero six it is running, okay? And what is the
password? The password is root okay all these details, okay?
All these details required for this MySQL, this local host, port number, Username, password, everything
we have to provide here in this statement. So, first let's provide the url like a via JDBC. I would like to
connect to mysql server okay uh which is installed in my localhost in which port number colon double
three zero six port number. As you can see here double three zero six i have to give that port number,
okay? I have to give that. Then, slash. In this mysql server, I would like to connect to one of the
database. In this MySQL, So if I say OK here, I'll get connected to the MySQL server. In that, I need to
connect to one of the database that is QFox.
So that database name you have to give after this slash QFox. Let's say I would like to connect to the one
of the database inside this MySQL server. That is QFox.
Now here, I need to give the username and password. Username is root. Password is also root, right?
How to connect to that MySQL server? Root root is a username and password like this.
this is the first step you have to do for the mouse and add throws declaration okay you have to do try
catch in real time but for now to make your explanation simple i'm just going with this uh throws which
will ignore this uh exception
that is coming here fine now for the mouse on get connection what is the return type connection okay
this is going to get connection method is going to return you the connection so here i'm going to say
connection connection is equal to okay this is a variable kind of thing
So, hold the Amazon connection and say create local variable.
Okay. Connection. Connection is equal to driver manager dot get connection of these details you have to
give. Let's close this so that we'll get extra space like this. Fine. So, we created a connection.
This simple line, guys, will make you, okay, when you write this Java programming line, okay, in the Java
programs and when you run this, this will get you connected to the QFox database inside the MySQL
server via JDBC. Okay. via JDBC, okay? Via JDBC, from java programs, you are going to connect to this
qfos database of this mysql server, which is installed in your local machine and running at the 3306 port
number fine so uh now uh but when i run this, nothing will happen, guys, okay?
Even though it's connected, we don't know whether that is connected or not, whether this is really
happening or not. To make sure that this connection happened properly, okay, so we should know that
we should have the results coming, right? So, for that, I'm writing this extra code. It's not compulsory to
write this code, but just to confirm this connection happened or not. I will say if connection dot is closed.
Is closed means not connected. This will return true. This connection dot is closed will return true when
the connection is not there. But if the connection is there, it will return false. so i'll write a if this not
okay not operator in java not operator is this one if not of connection dot is closed okay if not of
connection dot is closed what will happen?
If connection is not closed, it will return false false of uh not of false is true, so we'll go inside this okay
the connection is established, then we'll go inside this if condition, simple words. Now here i will say
[Link]. I'll say, connected to qfox database in mysql server okay this is what so when i run
this so when you run this statement when you run this statement this particular code inside this java
program the connection will be established to this qfox database of the mysql server and to confirm that
this will we are executing this part okay If you get the result as connected to QFox database here, that
means we can think that it got connected. So run this now, right click on this [Link], run as Java
application.
After saving, just run this. So here under the console, we got connected to QFox database in MySQL
server. That means by using this simple line, we have connected to the database. I'll write a comment in
the Java program saying that, okay, connecting to QFox database. database in mysql server, okay? In
MySQL server, I got connected to the qfox database. Next thing is, after connecting, what i want to do,
after connecting to this qfox database in mysql server, I would like to execute this uh table okay i would
like to execute one query on this particular EMP. Let's say i would like to uh like uh as you go to the
select star from emp1 table. So if I run the same select star from EMP1 SQL query or statement in this
MySQL workbench, I'll get this result, right?
okay? Till now, I have inserted three records from the mysql workbench, but the fourth record i would
like to insert from the java programs. So how to insert that? I have to write the one of the insert
statement like insert into emp1 values as four comma finish that statement i would like to express
statement i would like to as good now here uh creating creating a
Statement. Statement means sql statement. Creating a sql statement. Statement and executing it. What
is a sql statement i am going to execute and create and execute? The SQL statement is to insert another
record into this uh emp1 table so far in the emp1 table of this kfx database, we have three records
already inserted. We have one around two one three third Now, I would like to insert a fourth record,
but from the Java programs, I would like to do that. Here, I connected to the database. Now, I am going
to insert one of the statements. For that, we have to say connection dot. First, I have to create the SQL
statement. Connection dot create. What is that? Connection dot. Here, we have that.
Connection dot create. Same thing. Connection dot create statement. connection dot create statement
this one this one i have to select so in this i'll write a sql statement that i would like to execute okay so
that i want to like to create so let me write that so here we should not be writing i guess this is just for
the creation of the statement guys it's not creation connection dot create statement it is returning you
the statement okay statement so here statement statement is equal to over the mouse and say create
local variable so statement statement is equal to connection dot create statement now statement dot
statement dot execute execute what is that i have to execute i have to execute okay normal one minute
i will take this normal execute option guys okay so statement dot execute function that's it okay nothing
more than that
I have to write this [Link] string string string option okay so here in this I am going to write
an SQL statement. Okay? So first I need to create a statement, guys. Connection dot, using this, I can,
connection dot create statement. Then using the statement, I have to say [Link] in this I
have to write the insert into, SQL statement. Any SQL statement you can write here, guys. Not only
insertion. Another thing also you can write. Insert into what is the table name in the QA Fox? What is
the table name? The table name is EMP1. Okay. Insert into EMP1 the same kind of insert into EMP1
values. Values as 4 comma Dinesh. Okay. 4 comma Dinesh. Close it. So this is the SQL statement I am
going to run from the Java programs.
Fine. This has been written now. Now only thing I have to do is save it. Run it here. Okay. so the
connection will happen here to the qfox database of the mysql server. The connection will happen. After
connecting to this qfox database, inside that, into the emp1 table, we are inserting a new record with
the values for Dinesh. This is happening from the java program, not from the mysql workbench. Run this.
Run as java application. So connected to database and uh this would have been inserted because the
program institution has completed. So now go here to the mysql workbench. Let's confirm whether Here
I have not, from the MySQL workbench, I have not inserted any fourth record. Here only three records
are there.
I have not inserted any fourth record from the MySQL workbench. But when I say select star from EMP1,
I got four records. How it is possible? Because from Java programs, I executed this particular SQL query
statement, not from the MySQL workbench. That's why we got the fourth record also. Similarly, we can
do a lot of things, guys. Let's say I would like to this time execute another SQL statement. Like I would
like to delete the second record. so from this table, I would like to delete the second record. That is like
uh having the ideas too okay so how to write that? Delete. Delete from emp1 where id is equal to 2
Okay. Delete from emp1 table name where id is
equal [Link] I run this sql statement, what will happen? The second record will be deleted. Okay. The
second record will be deleted. So let's run this. Let's run, save this and run this, right-click run as Java
application. Okay. So when I run this, connected to database and this code executed, and when I go here
again, if I say select star from EMP1 from MySQL workbench, now you got only three records. Second
record has been deleted from the Java programs. Okay. From the Java programs, we connected to the
KFox database of the MySQL server. And thereafter, we executed this SQL query. Okay. which will
actually delete the one of the record from the empty one table, which is having the id value as two. So
like this, we can perform any, we can attribute any type of sql statement here.
Fine. This is possible. So insertion is possible. Deletion is possible. Okay. Updation is possible or
whatever it is. All the sql statements can be executed like this. Now, the next thing is, next thing is this
time, I would like to do one thing. Okay. Now, Whatever the current table, EMP1 is there, the current
data is like this. ID, name, column. Under that, three records are there with IDs as 134 and names as
Arun, Tarun, Dinesh. All these details, I would like to read from this. I would like to read these details, I
would like to read from this, okay? I would like to read all these details and display in this Eclipse ID from
here, okay? So how to do that? So I'm taking this example for a purpose, guys, okay? So let me explain
that purpose. If I say statement dot execute, earlier what I used? Execute I used, okay? So this time I'm
not going to use the normal execute and instead I'm going to use execute query, okay? Instead of
normal execute function, I'm going to use execute query. in this, I have to provide the SQL, okay? So
here i am going to provide an sql like uh select id comma name from emp1 table. Like this, I would like
to write, okay?
This SQL statement i am going to write. And this sql statement is going to give me multiple records,
right? Select ID comma name from emp1 is going to give me multiple records, not single record. This will
retrieve multiple records. common records, it will retrieve three records. Now, in order to read, save
these three records, I have to do something. Over on this attribute query, it will result in a result set. So
here, I will say short form like rset, variable name rset and over the mouse here and say create local
variable, result set rset. So here, all the records, three records retrieved from this EMP1 table will be
stored in this rset. Now, I will create a while condition. Okay. In Java, there is a while condition, while
loop.
So, if I say rset dot, rset dot, rset, while rset dot next. Okay. While rset dot next. So, are there any
records in the rset? So, now, select id, comma name from emp1 will give you three records. Right. Three
records. so i said dot next will see, like, how many records are there? Three records. Yes, this will return
true, guys. Okay? While true means you will go inside the while loop. Now, here, what you will do is i'll
retrieve the id and EMP1. How to do that? How to do that? I have to say rc dot okay uh rc dot uh what is
the method guys get get i guess okay get inter okay get int [Link] and I have to give the column
name.
What is the column name in this table? ID column name. So I have to give the ID. ID is of int type, int
data type, right? While creating the table, you created this ID as int data type. So that's why we have to
use getint, [Link]. So this will retrieve the ID value from the first record. From the first record, it will
get the first iteration, first record. So it will return you int. int EID, employee ID. I'm just giving another
variable name like EID. In the EID, this retrieved record from this particular id will be stored. From, for
example, in the first record, one is there. One will be, one from the id will be retrieved by this function
and that one will be stored here.
Similarly, I need to get this Arun, okay? Arun. Arun is a string, guys, okay? String, where care or string.
So, for that, we have again rset dot get to string rset dot Get a string, I have to say. Okay. Column name I
have to give. The column name is name. The column name is name. For the mouse, it will return you a
string. So, ename, employee name is equal to. Okay. For the mouse, create a local variable string. It will
come like this. Now, let me print. [Link]. Okay. EID. EID plus some space plus ename. Okay.
Like this, you have to say. EID plus ename. Now, what's happening here? First, it will select [Link]. It
will check how many records are there, three records.
Since three records are there, okay, it will go inside the while loop. Now, it will retrieve the, from the
under the id, first record, one will be retrieved and saved into this eid. And second thing is, it will
retrieve the arun name from the name column. Arun will be retrieved and saved into the ename now i
am printing the eid and ename. So, one and arun will be printed. After that, Okay, after that, again, this
while condition will be checked. So, there are two more records. That is, the second record, third record
are there. So, it will second the second record and uh what is the id of the second record? Three. Three
will be stored into the eid then rset dot get string of name.
So, what is the name? Tarun. Tarun will be stored into the e name. Now, those two three things like
three and tarun will be printed here. So, that is the second thing now third uh now again while condition
rset dot next So, any more records left, only one more record is left, this 4 Dinesh. So, 4 will be saved
into EID, Dinesh will be stored into Ename, they will be printed. After that, again, the condition. When
condition is checked, all the three records have been completed. So, no records left. So, it will come out
of the while loop. So, here, what's happening? We are retrieving all the records from this table, okay,
and then retrieving them from the table, reading them, okay, reading the retrieved records from the
statement and displaying it here.
Okay, converting
them into java program and displaying it here. So that's what we are doing. Right click, run as java
application. If I say that, so what's going to happen? You see, all the data from the table, one Arun, three
tharon for the image got displayed here, okay? So why i have to explain all these things? Just because of
this as you carry guys okay if you say statement dot execute only simple statements like insert into,
okay, update, all those things you can give that. But if you want to read, read from the table, okay, of a
particular database. Then, okay, if you are getting multiple records as a result of this particular thing,
then you have to use azure query okay azure query this function just just to explain this azure query and
what is possible with that, I have to create this example,
guys, [Link] you got all the details from the table. All the details in the this emp1 table, okay, of this
qfos database are now displayed in your eclipse IDE. so like this, we can perform lot of things from the
java programs, okay? This is java program guys from where we connected to the database. Then we
exuded the query statements and all, okay, to get our results. So finally, finally, what we can do is we
can close the database guys okay so this this connection is opened here. So it's a good practice to close it
also, right? After you are done with all the things uh with the, okay? of you are done with all the things
that you want to perform on one of the table of the database of this mysql server, then at the end you
need to close the connection to that particular database.
How to close the connection? Here you have to say, connection dot close it. Simply close it. Okay? So
here close means it will get closed. Just to check whether it is really closed or not, I will write this
statement if if connection is closed, If it is returning true, then connection to QFox database in MySQL
server is closed. I will display this. Now run this and rightly run as job obligation. So first it will get
connected to QFox database. Then it will retrieve all the records and read the table data and display
here. After that, after the work is completed, the connection to the QFox database in MySQL server will
be closed. so here we have to use a close function so guys so overall what is all about JDBC?
What is JDBC? jdb is a way where you can write the java program by connecting to the database, okay?
In this example, we have connected to the mysql server database and then perform operations there all
since nothing but jdbc guys okay now tomorrow tomorrow mysql bicycle is one of the db software,
right? Database software. similar to mysql database software, there are several other softwares like
oracle db software is there, okay? And many other database softwares are there. For MySQL DB
software, okay? For MySQL DB software, we have to download this mysql java java connectivity driver,
okay? Connectivity driver we need. For other oracle db software, we need other drivers okay for arkin
for example here you go to mvn repository and search for Arkin.
sql i mean oracle uh what is that uh java sql sql java connector connectivity or connector, whatever it is,
okay? Connector will be fine so uh here it is not coming. You see, for mango db is another thing. Other
than Oracle, we have mango db also as a db software. For that, Java driver, Java connectivity driver is
there. For every database, there will be separate connectivity drivers, guys, okay? for MySQL, we have
connectivity drivers for other things, other type of drivers will be there. So this driver will be, so which
type of driver we have to use? We have to use the mysql java connectivity driver for this uh my for
connecting to the mysql DB. For connecting to other database like mango DB, you need other drivers,
okay?
This will not work. MySQL Java connector driver will not work with the mango db okay for mango db we
need for mango db okay software and server or whatever it is. We need other type of driver that is a
java connectivity driver for the mango db okay so every database has its own driver which will allow it to
connect from the java programs. From the java programs we can connect to the databases using the
drivers of that particular software. Okay? So like this guys. This is one more thing. So tomorrow you may
not be using all time like uh say mysql database server you'll not be using mysql right every time. here in
this example, I showed you how to connect to the mysql database from java programs and how to
perform operations on the tables.
But tomorrow you may get another database. Then you have to change the driver guys. Okay. Yes. You
need to simply change the driver. That will be enough. Okay. Everything will be same. So all the things
like, uh, like whatever i explained, if you have, if you get a different, uh, database software, you can
search on the google and get the similar kind of steps, like how this works in the, rql how this works in
mango db like that. And then you can do that. Okay. that is the only difference, guys. So, guys, this is all
about the JDBC, okay? JDBC stands for java database Connectivity.
And in this video session, I practically showed you how to connect to a particular database from your
java programs and perform operations on one of the tables of the, one of the database in that particular
server,
okay?Database server. So, that's it guys see in the next video session. Thank you. Bye.
Part 85:ODBC
Hello, everyone. Welcome to part 85 of sql for beginner series in this video session i am going to explain
about odbc so in this video session i am going to explain about odbc
odbc stands for object database connectivity okay odbc stands for object database connectivity so
before i explain what is odbc okay before i explain what is odbc we have to understand what is JDBC.
Okay. We have to understand what is JDBC. I already explained what is JDBC in the previous video
session. So let me explain it again at a high level. Let's say there are some java programs. Let's say this is
a set of java code.
Some Java code is written here. These are the lines of code in java okay if you are writing the java code
in such a way that okay if you are writing the java code in such a way that using this java code, You are
trying to make a connection to a database in MySQL server. So by writing some Java program, using the
Java program, if you are connecting to a database in a MySQL server, this concept is known as JDBC.
What is JDBC? Connecting to a database in MySQL server from the Java programs. How it is possible?
With the help of JDBC only it is possible. Without JDBC, you cannot connect to a database in MySQL
server from the Java program. These are Java programs.
Let us say this is Java code. You have written some Java code here and if you want this particular Java
code to connect to the database in MySQL server, then we need JDBC. Without JDBC, we cannot do this
connection. This concept is known as Java Database Connectivity. JDBC stands for Java Database
Connectivity. this connection is possible with the help of JDBC driver. There is something known as JDBC
driver. Okay. So we have tried some Java code and we need to configure this Java project with this JDBC
driver. Okay. JDBC driver. Then only we can write the code in such a way that it can connect to this
database in MySQL server. Okay. Without JDBC driver, we cannot connect to the database in MySQL
server from the Java programs.
And all this concept together is known as JDBC. All this concept is known as JDBC. JDBC uses jdbc driver
for making the java code connect to the database in the mysql server. Now, guys, in this video session,
our focus is on ODBC, not JDBC, okay? So, it's ODBC. Why we need ODBC, guys? Okay? We have JDBC,
right? But what is the requirement for using the ODBC? Let me explain that. So, till the previous videos,
in the previous videos, we have used mysql workbench client. Right? We have used mysql workbench
client. For what? This is mysql workbench client, guys. Okay? MySQL workbench client. This is a client.
And using this client, from this client, we can connect to the database. That is mysql server we can
connect.
From this mysql workbench client, we can connect to the mysql server. Okay? MySQL server we can
connect. So here, MySQL server, which is installed in my local machine, That's why localhost and it's
running in W306 port number in my machine itself. And then its username for connecting to this MySQL
server is root and again password is also root. So if I say, okay, from this MySQL workbench, MySQL
workbench client will make a connection to the MySQL server. Okay, all the databases, all the databases
which are available in this MySQL server are displayed here. What are the databases that are there in
this MySQL server? We have QFox. we have circular, we have sys, and we have world. In this, one of the
database, that is QFox database, I created this QFox database in one of the previous videos.
But coming to the other databases, that is circular, sys, world, this came by default when I installed
MySQL server in my machine. So these databases are by default. They are by default available in this
MySQL server, but coming to QFox, I created my own. I created this QFox database so there are four
databases inside this mysql server and in order to connect to this mysql server we need mysql
workbench right using mysql workbench we can connect to we can connect to what guys using mysql
workbench we can connect to all the databases that are available in the mysql server okay So here in
our example, we have four databases. One I created by me and the remaining three came from the by
default with the MySQL server.
Okay. Fine. So now guys, MySQL workbench client to connect to the all databases that are available in
the MySQL server. Fine. So here, here, why we are connecting, why the MySQL workbench client is
connecting to the MySQL server. Okay. Why the MySQL workbench client is connecting connecting to
the mysql server for what purpose the mysql client is connected to the mysql server the purpose is to
access the databases, okay? Here, MySQL server has a list of databases. One database created by me
and remaining came by default in the mysql server. So in order to connect to this existing four databases
which are there in mysql server, we have to connect to this mysql server by using the mysql workbench.
That's the purpose of mysql workbench client.
The purpose of the MySQL workbench client is to connect to the MySQL server having this databases.
Okay, that's fine. So we can access the, if you connect to the MySQL server using the MySQL workbench
client, we can access this databases. Why we need to access the databases? Why we need to access this
databases? So if we can access the databases, then we can create the tables, delete the tables, alter the
tables, update the tables. We can do all the operations around the tables and all the things under the
database we can perform. Okay. so here, MySQL workbench client is connecting to the, connecting to
the mysql server for accessing the databases so that, so that we can perform operations on the different
things that are there in the databases.
Like tables are there, okay? A lot of stuff, indexes are there, views are there, like the many things are
there in the databases to perform operations on all those things, okay? We need this mysql workbench
client to connect to this database in the mysql server. Anyhow, just to connect, just for this mysql
workbench client to connect to this uh databases in the mysql server, we need things we need a ip
address of the, IP address of the MySQL server. Since MySQL server is installed in my machine, you don't
have to provide the IP address. Localhost will be fine. Then this MySQL will be generally by default
running on the W306 port number in my machine. So localhost W306 and some username and
password will be required for connecting to this MySQL server.
So as explained in previous videos, when I installed this MySQL server, I gave the username and
password for the MySQL server as root and root. Both are root only, username, password. So, with these
details, MySQL Workbench client can connect to the MySQL server and access all the databases that are
there inside this MySQL server. So far, so good, guys. So far, so good. Now, you understood what is the
importance of MySQL Workbench client. Now, this MySQL Workbench client, in order to make this
connection to this MySQL server internally, MySQL Workbench client, this is a tool, guys. MySQL
Workbench client tool, right? Okay. This tool internally uses a driver that is jdbc driver only. Okay. Here
JDBC driver is not only required for the java programs to connect to the mysql server, but also it is all,
but also the jdbc driver is used by this mysql workbench client internally guys you don't have to
specifically specify.
Okay. You don't have to download this or in case of mysql workbench client so you don't have to
download this driver automatically internally. This MySQL workbench client will have this, uh, jdbc driver
it internally uses this driver to make a connection to the mysql server in order to access all the databases
that are there in the mysql server okay here internally jdbc driver is being used by this client tool but
coming to other tools there are some other tools also guys there's a tool like sql odbc okay connectivity
okay tool okay so what is that tool odbc sql odbc query query client tool okay query tool guys okay this is
query okay sql odbc client okay query client tool so here so far i have, I have connected to the mysql
server using the mysql workbench client.
But now i am saying that if we have to connect to the same MySQL, okay. If you have to access the,
access the databases by, by connecting to the MySQL server. If you have to access the databases by
connecting to the MySQL server via this SQL ODBC query tool. This query tool is an alternative for this
MySQL Workbench client tool. Earlier, in the previous videos, I have used MySQL Workbench client tool.
So we can also use another type of tool, guys. In place of this MySQL Workbench, we can use SQL ODBC
query client tool. Okay. SQL ODBC query
client tool also we can use. But guys, for the sql odbc query client tool to connect to this databases in
the mysql server, this client tool requires a different driver.
Here JDBC driver is uh internally used by this client tool, workbench client tool. But coming to sql odbc
query client tool, jdb is not used. Okay. JDBC driver is not used. Instead, ODBC driver will be used. Okay.
Instead, ODBC driver will be used. Fine. So now you understood, right? Why we have to learn ODBC?
ODBC stands for object database connectivity. And here we have ODBC driver, okay? Object database
connectivity driver. And this driver is required when are you when we are using, okay? When we are
using SQL ODBC query client tool in place of this, okay? Instead of this MySQL Verbench client tool, okay
client tool, if you are using SQL ODBC query client tool, we need ODBC driver for connecting to the
MySQL server for accessing the databases.
So in this video session, I am going to explain about ODBC, okay? And in order to explain about ODBC, I
have to explain about this SQL ODBC query client tool and how this client tool connects to this MySQL
server database via this ODBC driver, okay? So all these things I'm going to explain in this video. Our
focus is on ODBC now. I'm going to explain about ODBC, SQL ODBC query client tool, this ODBC driver,
and how it can connect to this MySQL server database. So let me practically show you all the things. So
the first step here is we need to type ODBC here. Already ODBC is there. I thought ODBC has to be
installed and downloaded here, but already ODBC is there in my machine, as you can see.
We're getting this option. When I type ODBC in this window search text box field, I'm getting this ODBC
data source in 64-bit. Select this. Okay. Select this. How can I get this ODBC by default, guys? Okay. How
the ODBC has entered into my machine by default? The thing here is, the thing here is, when you have
installed, okay, when you have installed MySQL, MySQL software, okay, dbms software. In one of the
previous videos, I explained how to install and configure mysql software, right? When you install the
software, this software came with all the default drivers and all the stuff. So as part of that, ODBC also
came by default, okay? ODBC is also installed by default, guys, okay? When you install mysql software,
automatically this odbc also got installed.
So now, go to the drivers. tab Under this, you should see these two things, guys, okay? We need these
two things. In order to in order to make the connection to this mysql server via this uh this sql odbc
query client tool, okay? Using this sql odbc query
client tool, if you want to make a connection to the databases in the mysql server, okay, then we need
odbc driver. So this odbc driver is nothing but available here. I have not installed or configured, right?
Automatically it is there. How it came automatically in this my machine? Because when i install mysql
software, okay, MySQL RDBMS software, automatically this software installed this odbc related stuff.
Okay. So when you type odbc here, you will get this and then under the driver tab, as you can see, these
two drivers are there.
Okay. ODBC drivers are already there for example for example let's say you have not installed mysql
software. Let's say you have not installed mysql software and this particular odbc is not available for
you. Okay. This particular odbc is not available for you. In that case, what you will do, since i installed
mysql software in one of the If ODBC is not installed in your machine, what we have to do? We have to
follow some steps, guys. Okay. So open Google. Search for MySQL. Okay. Connectors. MySQL
connectors. Just search for MySQL connectors. You will get this link, guys. [Link] slash, I
mean, products connector. This particular URL you will get. Just click on this. It will take you to a
particular page. And here, MySQL connectors are there.
And as you can see, the first one, this is not related one. As you can see, the second one, ODBC driver for
MySQL is there. You have to download this driver. All these things you have to do. You have to
download this if it is not available here. If I say ODBC here, it's directly coming. And if I select drivers, I
can see the drivers. This ANSI driver and Unicode driver of the MySQL ODBC is already there. But if these
things are not there for you, if your system doesn't have the mysql installed, then you have to manually
go to this [Link] products connector. Then here odbc driver for mysql is there. Just click on this
download, okay? You have to download it no problem guys we can install okay even though it is
available we can install also so so if you don't have that odbc in your machine, you have to install from
this particular place.
You have to download and install the odbc from this place. ODBC driver should be installed from this
place. here my mysql community downloads and connector odbc is there. Scroll down. And we have to
go with this windows uh 64 bit msi installer download this okay download this so it's around the 14 m uh
m or something. So 14 mb or something. And here it is asking you to log in. Click on Login, guys. Click on
login so or uh you should have an oracle account guys okay not to download this particular ODBC, you
need to have the oracle account. So, if you don't have, you can create an account from here. Create
account. You can see an option here, create account. If you have the account, I already have the account
details, okay?
So, I will directly give the account details. [Link] And here, I will give my password.
Click on sign in. So, I got logged into my arkyl account and the odbc driver should be downloaded now.
Okay. Begin your download some download now mysql connector for odbc windows 64 bit okay you
have to download this. Click on this. The driver will be downloaded. Okay. So, now we have to download
this and install it, guys. Okay. You have to download and install this. So, it's taking some time. Already I
downloaded, guys. As you can see here, this mysql connector odbc is already there. I don't have to
download again. So, let me cancel this. Okay. So, it's already there in my downloads folder. So, if you
don't have this, you can download this, okay?
So, just double click on this mysql connector odbc and click on next. So, some options are coming, click
on next. So, MySQL, since it is already there, I'm, since odbc is already there in my machine, I'm getting
modified. In case of you, you will not get this modify, repair, remove, okay? You may get the installation
wizard only. So, here i will select to modify, okay? Just to make sure that we'll go with the next steps. So,
click on next. Okay. So sometimes will take some time guys. So next back. Okay. So if i say modify, right,
it's not going for, it's going now. Okay. Some problem is there. That's fine. I'm just going and installing.
So let's say if you don't have ODBC, this is a process.
Like you have to install the odbc driver using the default options. So ODBC got installed now. ODBC
driver got installed in your machine. Just to confirm that, again you can go to the same ODBC and select
this ODBC data sources. Go to the drivers. You should see this ANSI driver and Unicode driver. By
default, if you don't have this ANSI driver and Unicode driver, you have to download this MySQL
connector ODBC for Windows 64-bit. Since my machine is Windows 64-bit, I downloaded this version
and installed this so that you will get these options. If not available, you have to install this and you will
get these options under the drivers tab. of ODBC fine next thing is next thing is we have to create a data
source, okay?
We have to create a data source. For that, what we have to do? We have to create a data source third
step is after downloading and installing MySQL ODBC driver, and if you find this ANSI driver and Unicode
driver in the drivers tab of that ODBC, then up to here it is completed. Fine? Then, we have to create the
data source name. creating the data source name. Why we have to create, I will explain later. So for
that, just select this system dn dsn okay system system data source, okay? We have to create the data
source name here. Select this mysql connector ODBC. Or these are existing ones, guys, okay? You can
remove them because i was working with this odbc from long time, so these options came.
You can remove them, okay? So we have to freshly create one. So now we don't have anything, okay?
Under system DSN, we don't have any. data source. Here we have to create the data source. Okay? We
have to create the data source. You will understand what is data source now after i create. So data
source uh now there is no database. Click on add. And you will get this kind of deluxe saying create new
data source. MySQL. You have to select this ansi driver.
Okay? MySQL ODBC ANSI driver and click on finish. This MySQL connector odbc will come. Dialog will
come here some give give some name guys. Let's say i would like to connect to qf of database okay qfox
database in mysql connect okay connecting so connector so qfox database in mysql qfox gb in mysql
server connector some name i am giving for this data source okay so because i would like to connect to
qfox database in mysql server okay so that's why i'm giving qfox here there are four databases in mysql
server right i showed you
So in that I would like to connect to the one of the database that is QA Fox. So I am giving this data
source name as QA Fox DB MySQL connector. Okay. So here you have to give the localhost. Okay. IP
address of the MySQL server is MySQL server is installed in my machine only as part of the previous
videos. Okay. I explained how to install the localhost. Here port number will be 3306 and here username
is root. MySQL server username is root and password is also root as I explained here. since i would like
to connect, access this qfox database in this mysql server, so the list of databases will be displayed here
or in the mysql server, whatever that is installed in my machine.
There are this many databases okay so i want to say i want to access this qfox database,
so i am selecting the QFox. And after providing all these details, you have to find out whether you can
connect to this qfox database in the mysql server or not. For doing that, you just click on the test if you if
you get connection successful, that means you are able to connect to the database, okay? MySQL
server, qfox database, you are able to access and connect. Okay? Click on OK. And you see, the data
source got created with the name qfox db mysql connector. Click on OK. Done. Okay? So, we have
downloaded and installed mysql odbc's driver. After that, what we did, we created the data source
name, okay?
And in the data source name, I mentioned that i am going to access the qfox database in the mysql
server. i provided all the username and password. You don't have to give username password again,
okay? Already, the data source name has that thing. Now, we need to have, similar to this mysql
workbench, I told you, right? We need, we have this sql odbc query tool. Here, I was explaining, right?
Using MySQL workbench client, which uses jdbc driver for accessing this database by connecting to
mysql server. Here, we are going to use another tool that is sql odbc query tool, which needs odbc driver
so already set up the odbc driver. I already download and install the ODBC driver. And also I created a
data source.
Second thing is we need to create data source. Okay. So in data source, what I provided, I provided the, I
provided the IP of the SQL server. Since it is my machine, I mentioned is a local host and the port
number and the database that I want to access from the MySQL server using this client tool. Okay. ODBC
query client tool, whatever the database I want to access, I provided that. So after providing all this stuff,
okay, after providing all this stuff, okay, so now this client tool can access this database in the MySQL
server. So for that, we need to download and install this query tool, right? We don't have this query
client tool, okay? This one, we have to download and install.
So how to download and install this SQL ODBC query client tool? So again, Google, guys, for everything,
Google is there.
So SQL, type SQL ODBC query. Just search for this. You will get a lot of links, guys. I preferably select this
[Link]. So, SQL query client tool. Click on this. So, yes, this is a URL. This is a page where
you have to go. And then click on this download now. SQL query client tool using ODBC. We'll start
downloading. So, thank you for downloading. It started downloading, guys. Already I downloaded, guys.
So, you don't have to download again. see this is downloaded already. So I will simply cancel it, guys,
okay? I don't want duplicate, so i'll cancel it so this uh this this client tool software is downloaded
already.
You can install it, okay? Now let's install the query client tool. Welcome to the query tool, SQL query
tool. Using ODBC, we have to connect. This tool uses odbc driver and odbc data source, okay? Data
source for connecting to the mysql server, whereas workbench internally uses JDBC to connect to the
MySQL server. You don't have to configure JDBC here in case of Workbench. But in case of this SQL
query tool of ODBC, we need ODBC to be installed, right? I have manually downloaded and installed the
ODBC in my machine. Fine. So then next thing is, next thing is, here we have this next option. Click on
the next. I agree. Click on next. Then the place where it's, just click on next, guys.
You don't have to change anything. Click on next. Installing query tool. So, we just have to install this
query tool, guys. This is like a workbench only. So, where you can create the uh where you can write the
sql statements and run, okay? Where you can, where you can write the sql statements and execute
them from this tool also. Similar to workbench, we can write the sql statements and run on the
databases of the mysql server. So, it's uh being installed. It will take bit time. So let it complete the
installation part. So I got a user access control. I just selected S guys. After that, the installation started.
So it will, okay. As part of security, we'll get a kind of S or no kind of thing, user access control.
So you need to allow this software to be installed in your machine. So when you say S, it will be installed.
Now it has to complete this progress. Let's wait for it to complete. Okay. So, the installation has been
completed. You just need to click on the close button. So, once the close button has been clicked, the
the sql odbc query tool has been installed in your machine. So, where you can find it? Maybe on your
desktop, you will see this kind of shortcut created. Okay? This kind of sql odbc query tool shortcut will
be created shortcut okay shortcut so you just need to double click here. You will get this kind of dialog
when you open. Select this machine data source, machine data source.
And in this, you should find this, you should find this source, okay? That is a data source. We created this
data source name, right? If you remember in the last step, I created this QFoxDB. For connecting to the
QFoxDB, which is all in the MySQL server, okay? I gave this a name while creating the data source, okay?
while creating the data source in the previous step, I created this name, okay? This data source got
created in the previous step. Fine. So, this should come here. You have to select this. Now, using this
data source right uh you are approving this query tool to connect to the mysql server and it should allow
you to access the qfos database in the mysql server, okay?
That is the purpose of the data source, okay? That's why we have to, after installing the odbc driver, you
have to create the data source like this, okay? For whatever the database you want to connect, you have
to give some name, and specify the database and the server and server access details and all the stuff,
username, password, everything to create the data source. And when you are using this query tool, it
will ask you to select this kind of data source. So you have to select the machine data source tab here
and select this QFoxDB MySQL connector and say, okay. Now you see it got connected to the MySQL
server and that we will be able to access the QFox database. So in the QFox database, as you already
know, EMT1 table is already there, right?
Here you see in the MySQL workplace, there are four DBs. and uh via this uh sql odbc query tool, okay,
we are able to access only one table. So let's confirm this particular table belongs to which tv so if you
expand here, you can find it out. Under QFox, we have EMP1, okay? So EMP1 table belongs to qfox
database. Here, that means using the SQL, okay, ODBC client tool, okay, query client tool, we are able to
connect to the qfx database in the mysql server. Now, how to, why we have to connect to this database,
QFox database? So that we can perform operations on the objects of this database. So let's say EMP1 is
one of the table of this QFox database. This is an object of the QFox database.
You can perform operations on this table. So how to do that? We can write some queries like select star
from EMP1 table. Okay. Select star from EMP1. Select this right click and say execute. So when I run this,
you see all the records that are available in the EMP1 table got displayed here. okay so so guys this is
how we have to use use uh this is how we have to use sql odbc query client tool for connecting to the
mysql server databases. Okay. Via the which driver, ODBC driver. Okay. Via ODBC driver. So now
tomorrow, tomorrow, let's say you can perform any operations. Not only this one, you can insert the
records into the table. Okay. All those things you can do.
Okay. All the things that you can do here with SQL statements, you can write any type of SQL statements
on this table, okay? You can perform here. That's fine. Now, I want to connect to a different database.
Here, QFS database I connected, right? Now, this time I would like to connect to another database. For
that, what I will do is I have to create a data source, right? What do we see? I have to say, click this and
system DSN. And you see this particular data source is created for you to connect to this QFS database,
right? QFS database in MySQL server. I'm going to create one more. here again, ANSI driver you have to
select say finish this time again uh this time which database, let's say here we have four databases right
uh let's connect to world database, okay?
In world database, what tables we have we have city country all these tables are there. So here, I am
saying world database, world db okay mysql connector now here localhost you have to say. Because,
why i'm saying localhost because mysql server is installed in my machine, so i have to say localhost If
MySQL server is at a remote machine, you have to provide the IP address of that particular machine.
Okay. The port number will be generally 3306 only. Okay. Here, username of that MySQL server is root.
Password for connecting to this MySQL server is also root. Now here, database, while selecting the
database, you have to select this world. Okay. So world database, which is there in the MySQL server
installed in my machine.
Click on test. Connection is successful. Say okay. Say okay. Now, from this, from this SQL ODBC, query
client tool. Now, current selection is qfox database. You are accessing the qfox database. Now, if you
want to connect to another database, file, say, new, say, query with current connection, okay? Select
this. Sorry, wait a minute say new uh query uh this one, okay? Query with new connection. This option
you have to select, not current. New connection you have to say. Say, new, query with new connection.
Say, data sources. So, from the data sources, what are the different data? So you have to go to this
machine data source, and this time you have to select another data data source so if you want to work
on this world database, you have to select this database, data source, okay?
So if you want to work with qfx database, you have to select this data source now i'm i would like to
work with the world database, okay, in the mysql server. So I am selecting this data source and saying,
okay. It got changed. So what are the tables available now? You see, there are more tables now. In the
world database of mysql server, we have city country country language and other tables are there.
Similarly, if you want to connect to other database, here we have circular database. If you want to
connect to circular database tables, what do you want to do? You have to, what do you have to do guys?
You have to create another data source. Okay. This is the same process for everything.
Okay. Go to system DSN. So existing data sources are these two data sources click on add select mc
driver click on finish here say circular circular db in mysql server. Okay. Connect, say here localhost,
localhost, this is just a name guys, you can give any name so that you can remember what you are going
to do. And here username is root and password is also root. And the database here is, I would like to
work with the circular database and test it, connection successful, say okay. Okay, another data source
got added to the list. There are three data sources here. This data source for working with the QFox
database. This data source for working with the circular database in MySQL server. This, uh, data source
for working with world database in mysql server.
Like that, this Click on OK. Now, how to change the, uh, now if i go to this, uh, SQL ODBC query client
tool, okay? Current selected database is world. If you want to change that, again say new, okay? Either
you can say query with change connection also, okay? When you say change connection, automatically
this will come. You can change the database to circular database. So, for each and every database, you
have to create a data source here, right? For each and every database, you have to created for qfox
database i have created data source. For a secular database, I create another data source for a world
database. Again, another database. This time, if you want to work with secular database, select this
secular database and say, okay.
Okay. So what happened here and say, okay. Yeah, it got changed guys. Okay. It got changed under
tables. We'll get the tables of this secular database. Okay. All the things of views, tables. Okay. And any
other things of the secular database will be displayed here. Now you can perform operations on this. For
example, if I say select star from actor, select star from actor and right click and then azure this you see
all the records from this actor table of the circular database will be displayed here and you can perform
any operations on this. Okay. You can write any queries on this particular table and do the stuff. Okay.
The same thing that explained as part of the previous videos so guys so at a high level, okay.
MySQL workbench, workbench client tool, okay? So this tool will be installed when you install mysql
server automatically, you don't have to install it separately, right? So this mysql workbench client tool
also internally uses. You don't have to download this jdbc driver. In case of java programs, you have to
manually download, okay? Download JDBC driver and configure the java project with the jdbc driver.
But in case of mysql workbench client, you don't have to download. Automatically, automatically, this
tool, this tool, will use jdbc driver internally for connecting to this mysql server okay you don't have to
manually download okay in case of mysql workbench but coming to the odbc driver okay but coming to
the odbc driver this odbc driver is also required for connecting to the databases accessing the databases
by connecting to mysql server same operation only but here
So, which tool is using this ODBC driver for connecting to this MySQL server and accessing the database
inside it? The tool that is explained in this video session that is SQL ODBC query tool. This tool. So, for
this particular client tool to connect to this MySQL server and access the database, we need ODBC
driver. And for this, we have to download and install driver. which driver? ODBC driver. We have to
download and install. Without downloading and install odbc driver, we cannot connect. But guys, but if
this mysql server is installed in your own machine, then this download and installing is not required,
right? By default with mysql server, okay, this odbc driver is coming, okay? In some cases, what will
happen is your machine will be here, some mysql server will be here.
So MySQL server will be installed in the remote machine. In your machine, MySQL will not be there. At
that time, You have to manually download this ODBC driver in your machine and install it. And then only
you can create the data sources for connecting to the MySQL server, which is there in the remote
machine. But in this video session, MySQL server is installed in my own machine. So I was not in a need
to install this ODBC driver. Without installing this ODBC driver also, I got the options to create the data
sources, right? But anyhow, in this video session, I showed you how to install this ODBC driver on your
own. Fine. So guys, these two drivers are the main drivers in the market.
ODBC driver and JDBC driver are the two drivers in the market which are required for connecting to the
MySQL server from different tools and programs. So we have to remember this ODBC driver and JDBC
driver while working with the SQL. While you are working with SQL, you should have some knowledge
about this JDBC driver and ODBC driver and where exactly we use this JDBC driver and where exactly we
use this ODBC driver. Okay, so this kind of basic knowledge you should have. So guys, this is all about the
ODBC. So hope you understood what is odbc and how it is different from jdbc and all. So that's it guys.
See you in the next video session. Thank you. Bye.
Part 86:MySQL Shell Command Line Tool
In this video session, I am going to explain and practically demonstrate on how to use mysql shell
command line tool. So, in this video session i am going to explain how to use mysql shell command line
tool. So, what is the purpose of using this mysql shell command line tool? Purpose is very simple, guys.
To connect to the mysql server, okay, and access the databases, okay? connect to the mysql server for
accessing the databases so far in the previous videos we were using mysql workbench client right
workbench client tool so this is a gui tool guys okay mysql workbench client tool is a gui tool let me show
you how this mysql workbench tool looks like we have to search for this workbench here workbench
and just select this. MySQL Workbench will launch. So this is a gui tool, this, okay? We have connected
to the mysql server from this uh mysql workbench tool so like this, and we were able to access the
databases, okay? After connecting to this mysql server using this mysql workbench client tool, we were
able to access the databases that are there inside this bicycle server now i am not going to use a mysql
workbench plane tool. Instead, we can use MySQL shell command line tool. The name itself says
command line tool, shell command line tool. Command line means you will not have the GUI version
here. In the workbench we have the databases are visible in a GUI format. Whereas in MySQL shell
command line, it is a command line kind of thing.
You will not see the GUI. Let me show you anyhow. So before I show you how this MySQL shell
command line tool looks, do we have to install it? Do we have to download and install mysql shell
command line tool? Is it required for us to download and install this mysql shell command line tool? The
answer is no guys, okay? You don't have to install it, okay? You don't have to download and install this.
So then how? Then how can we get this mysql shell command line tool? So this comes automatically
with the MySQL. When you install MySQL software in your machine, so with this MySQL software, we
also get this MySQL workbench automatically. You don't have to separately install or download or install
workbench.
When you install this MySQL software, along with the software, you'll get server. MySQL server you will
get. MySQL server you will get. workbench client you will get. Along with that you will also get this mysql
shell command, okay? Shell command line tool also will get. So, once you install this mysql software you
will get all these things. You don't have to install again. So, how to install this mysql uh mysql software in
your machine? This part, guys, I explained very long back in the same video series, okay? You can go go
to that previous video where i explained how to install this mysql software in your machine. Okay, I'm
not going to do that again. You can refer to the previous videos, guys.
Fine. So, hoping that you already have the mysql in mysql software installed your machine if you have
the mysql software installed in your machine by default, you will get this mysql shell command line tool.
Okay? Then how to find it? Yes, you have installed mysql software in your machine, but how to find this
mysql shell command line tool? Simple, guys. In the windows search, in the machine which has mysql
software installed already, just search for shell. Okay, just type shell here. You will get mysql shell, okay?
Like this kind of thing, okay? With a dolphin kind of symbol, which belongs to mysql anyhow. Just click
on that so this is this is a command line tool, guys, okay? It is a command line.
It's not a gi version. It is a commands. You have to provide the type the commands here to get the things
done. Now, by default, this mysql shell command line tool is referring to the js means JavaScript. But I
need to change this to SQL. where can i find the commands for, okay? Where can i find this mysql shell
commands? Simple, guys, and Google. Just go to google and search for mysql shell commands. Simple,
okay? Shell commands.
When you search for that, you'll get this link, like [Link] doc mysql shell commands.
Just click on that now you will get this mysql shell commands. This is a list of shell commands, guys,
MySQL shell commands that you can use now in the MySQL shell command line tool.
Fine. At present, we need one command for switching from JavaScript mode to SQL mode. For that, the
command is this slash SQL, okay? So, by default, JavaScript mode is there. So, from that, you want to
switch to SQL. You want to execute the SQL commands. So, you have to type this slash SQL, where in the
MySQL shell command line tool, right slash sql so before i execute this java script js is there now if i run
this you see mysql come shell command line tool got switched to sql mode now okay now you can run
the sql queries kind of thing here now that's fine in order to run the sql queries we have to connect to
the database right i mean you have to connect to the mysql server so without connecting to mysql
server we cannot perform anything on sql right using sql so how to connect to the my um
How to connect to this MySQL server? For that, we have a command like slash connect. We have to use
this command. Slash connect. Then after this, we have to provide root at the rate. Okay. Root is a
username, guys. Okay. Root is a username at the rate the server IP address. Since the server is in my
local machine, I don't have to provide the IP address. If the server is in the MySQL server is in a remote
machine, then here after that, you have to provide the IP address of that remote server. But since the
MySQL is installed, MySQL server is installed in my machine itself. I have to simply say localhost. It will
pick up. And in which port this is running, you have to say colon.
And generally, the MySQL server runs in 3306 port. So root is the username of this MySQL server.
Localhost is a, since MySQL server is in my own machine, I have to give localhost instead of IP address
and then say colon. Then I have to give the port number generally where the MySQL server runs.
Generally, MySQL server runs in the port number 3306. This is enough, guys, okay? this part is enough
now say
now enter when you enter, guys, creating a session to this uh mysql server please provide the
password. The password is also root, guys, okay? So where did i give the root as username and
password? In previous videos, guys, okay? When I installed the mysql software in my machine, I gave the
root as username and root as password for the mysql server, okay?
You just refer to the previous videos for this particular just enter now it is asking me whether you want
to save this password for future. I will say no, guys. I don't want to save the password. So, simply type no
and press enter.
Now, we got connected to this MySQL server, which is there in the local host. That is my machine, the
same machine, which is running at 3306. Now, here you see SSL is there. We have not selected any
database here. Database is not selected, but I want to find out how many databases are there in this
MySQL server in my machine. For that, you have to say show. Databases. This command you have to you
already know how to use these commands, right?
The previous videos i explained all these sql comments so databases will display the list of databases
that are there in this mysql server. Run this.
The list of databases which are there in the mysql server will be displayed here. And here, I would like to
select this qfox database, okay? I would like to, out of all these available databases, I want to work with
the qfox database. For that, what is the command? I would say use QFox, okay? This command also
explained as part of the previous videos. Just run this. Now, here, as you can see, here, instead of SSL,
QFox got selected, right? QFox got selected, right? Because I selected the database as QFox, okay? Now,
whatever the queries I run here, those will be performed on this QFox database.
I would like to see, like, under this QFox database of this MySQL server, how many tables are there? I
would like to find out, okay? I have to say that show tables, okay? This is a command. It will display the
list of tables that are there in this QFox database of this MySQL server. So, only one table is there, guys,
EMP1 table. so i would like to find out whatever the records that are there in this EMP1. So for that i
have to say select star from EMP1. Okay, run this. So all the employee records that are there in this
emp1 table will be displayed here. Two columns are their id and name. Okay, which i created. This table
was created by me only as part of the previous videos.
So I have not deleted this table. So it's there like that in the qfox database. Okay, so mp1 table. In that
emp1 table, there are two columns and three records.
One, three, four. arun dinesh are there. Okay. Now you can run any query here, guys. You can create
new table. Okay. Lot of things you can do from here. Okay. Lot of things you can. Under the qfox
database, you can create more tables also. Like create table. Okay. EMP2. Like this you can do that.
Okay. ID as uh int name as where care of 15. Okay. Let me create this. So say semicolon. Enter. Okay,
you have an error in your syntax, check the manual. Okay, where exactly the mysql server version for
the right syntax to use near, where care Okay, here some scanning mistake, is that just press up arrow
you will get the previous uh whatever you have type is the mistake i did.
Okay, here, direct care I have that i have to type where care Okay, that is correct. Now enter, you see
this time the table got created, zero rows, there are no records in this table. if i say show tables this
time, two tables will be displayed area only emt1 table was there. Now EMP2 table is also there. But in
the emp2 table, there are no records. If I say select star from emp2 you you are getting empty set. That
is, there are no records. How to insert the records? Insert into emp2 values as one comma arun okay
done query once insert another insert. Insert into EMP2 values as 2, Varun. Another row will be
inserted. Insert into EMP2 values as 3, Varun. Another record will be inserted.
Now, I would like to find out what is there in the EMP2 table. Select stars from EMP2. Now, run this.
Again, any mistake I did, select. There is a mistake at the select. Select. I have to type select. star from
emp2 or run this you see whatever the records are inserted, they are displayed here. One around two
one three turn in the emp2 table, okay? Which has id and name as a columns like this guys uh not only
from from the mysql workbench okay but also we can we can connect to the mysql server from this
mysql shell command line tool. And at same time, we can uh operate okay on the we can select the
database. We can create the tables. We can operate.
We can run different sql commands. Okay. On whatever the tables or any other things in that particular
database that we selected. So guys, uh, this is how, this is how we have to use mysql shell command line
tool. Okay. This is how we have to use mysql shell command line tool. So that's it guys. See you in the
next video session. Thank you. Bye.
Hello everyone. Welcome to part 87 of sql for beginner series. In this video session, I am going to explain
and practically demonstrate on how to use MySQL command line client. So in this video session, I am
going to explain how to use MySQL command line client. What is the purpose of using this MySQL
command line client? The simple purpose guys, the purpose of this MySQL command line tool is to
connect to the MySQL server.
and thereby access the databases for performing the operations on the database objects. So to connect
to the MySQL server, after connecting to the MySQL server, we can access the databases that are there
in the server and then perform the operations on the database objects of that particular selected
database. This is generally any particular client tool will do. Here, MySQL command line client is also a
client tool which can be used for connecting to the MySQL server and thereby access the database and
then perform the remaining SQL operations. So far, till the previous videos, we have used different client
tools. So that is one of that client tool is the main client tool we have used so far is like MySQL
Workbench. This is the main tool.
So MySQL Workbench. so using this mysql workbench also, it's a gui version, guys, okay? GUI version.
That means uh it's a gui kind of thing where you can see everything like databases their names objects
everything we visually okay visually i can show you here again. So just select this workbench, and uh this
is a mysql mysql workbench client using which we can connect to the database, and then you can see
everything visually. You see, everything is in a visual format. So this connection also is being done with a
dialog. You see, this is a visual dialog. Click on OK. when you give the password, it's getting connected to
the database. As you can see, all the databases that are there in this mysql server here, okay?
And you can run your sql queries here on this particular database objects in this section. Everything is
visual here, right? Lot of option visual options are there here. But later point of time, I explained you,
okay? I explained you, I put MySQL, MySQL shell command line tool, okay? shell command line tool. This
one is a not a gui version, guys. It's a command line, okay? It doesn't have GUI. It's a command line
command based command line based tool so after this, now i'm going to give another, okay? This is also
a client. This is one client. This is another client. Now I'm going to give another tool that is mysql
command line client, okay? This is another tool that is mysql command line.
This is also a client, okay? This is also a And this one also will fall into the command line based kind of
category. Okay. Command line based category. So about this MySQL shell command line tool I explained
in the previous video. And in the current video, I'm trying to cover the next command line based tool for
connecting to the MySQL server and then accessing the database and performing the SQL operations.
For that I'm going to use, I'm going to explain MySQL command line client in this video session. Okay. So
how to do that? simple guys, in the windows search here, Windows search, just search for mysql
command line, okay? Or simply search MySQL. You are getting this mysql command line client. Or you
can search for command line client, it will come.
Command line client also, it will come. You see, you will get this mysql command line client. Just select
this one. You see, the tool has been launched. It is directly asking you to provide the password of the
server that you want to connect. In my local machine, in the same machine, I installed the MySQL
server. I explained how to install this MySQL database software in one of the previous videos. Since
MySQL database software is installed in this machine, the server will be also there in this machine. And
also, you are getting this MySQL command line client by default, guys. Because when you install MySQL
DB software in your machine, automatically it will actually install the MySQL server automatically. It will
install the MySQL workbench client.
It will install the MySQL shell command line. It will also install a MySQL command line client. So this
thing also came by with the MySQL DB software itself. You don't have to manually install or download or
install it from other place. You will have this by default when you install MySQL DB software in your
machine. How to install MySQL DB software? I already explained as part of the previous videos. You can
refer them. So it's asking for the MySQL server's password. I'm giving. password as root because when i
install this mysql db software, I set the username and password of that particular software as root,
okay? You have to give the same thing. Now, so we got connected to the mysql server, okay?
So when I run this, the database got selected as QFox. Database changed. Now, under this QFox
database, Okay, what are the tables available? For that, another command is there like show tables,
right? Show tables. Now enter. All the tables which are there in this qfox database of this mysql server
will be displayed. There are two tables. This EMP2 table i created as part of the previous video, guys.
While explaining previous video, I created this emp2 table. Now here also i am trying to create another
table, okay? From the mysql command line client also, I am trying to create another table. Create table.
What is the syntax? I create table table name emp3 let's say, okay? So here also id int name as varchar,
varchar of 15.
So like this, I am just creating another table, emp3 table. The table got created, but it doesn't have any
records. Select star from emp3, if I say, you will see an empty table, okay? Your empty set is there. Now I
have to insert some records into this emp3 table. Insert into emp3 values as 1, Haroon, okay? So one
row got inserted. Insert into emp3. values 5 comma dinesh then insert into. EMP3. Values. Some 9
comma. Kiran. Like that i am just inserting some three name three records so now if i say select star
from. EMP3. I will get the table having the records like these three records i inserted just now. Those are
displayed. like this guys you can you can run any query okay you can run any query you can run the
delete statements and anything anything about sql you can run uh you you can uh using this mysql
command line client you can connect to the mysql server thereby you can run any sql queries to select
the databases show the tables and then then perform operations on from specific tables okay inserting
data into the tables and retrieving the records from the tables and all the stuff you can do here okay
So this is all about the MySQL command line client. So this will come by default with the MySQL DB
software. While installing MySQL DB software, you will get the MySQL server, MySQL workbench,
MySQL shell command line tool, and MySQL command line client also. So this will come by default.
Anyhow, you don't have to install. So hope you understood this session, guys. Thank you. Bye.
Part 88:Using Default Windows Command Prompt for Connecting to MySQL Server
Hello, [Link] to part 88 of SQL for Beginner Series. in this video session i am going to
explain and practically demonstrate on how to use default windows command prompt for connecting to
mysql server.
So in this video session, what i am going to do i am going to explain and practically demonstrate how to
use default windows command prompt, okay?
How to use this default windows command prompt for connecting to the mysql server mysql server and
thereby perform operations on the databases that are there in the server. First of all, this default
Windows command prompt comes by default with the Windows operating system. If you have this
Windows operating system installed in your machine, it can be Windows 10 or whatever it is, along with
this Windows operating system, you will get a default Windows command prompt. How to find it? so
just type this cmd command in this windows search bar, and you will get this command prompt app.
When you open this, you'll get this default windows command prompt. This belongs to the windows
operating system, guys. Using this default windows command prompt of we can also connect to the
mysql server okay using this default windows command prompt, we can also connect to the mysql
server.
In this video session i am going to explain how to do so okay how to connect to the mysql server, how to
access the databases using this Windows default command prompt and how to perform operations on
the tables and all those stuff using this default Windows command prompt.
So let me explain. Before that, in your computer, you should have MySQL server installed. I mean,
MySQL DB software should be installed in your machine. We have this MySQL DB software installed in
your machine. Then only you can use this Windows command prompt to connect to the MySQL server.
Without having the MySQL DB software, you cannot have the MySQL server, right? So the prerequisite
here is if you have the MySQL DB software installed in your machine, so along with this DB software, you
will get the MySQL server also, okay, which has the databases and all the stuff.
So how to install this MySQL server and how to install this MySQL DB software and how to get that
server, everything I explained as part of the previous videos, okay? So refer to the previous videos. if you
don't have the mysql db software installed in your machine you have the mysql db software installed in
your machine, then you can use default windows command prompt to connect to this mysql server and
thereby to the next steps. So assuming that you have the mysql db software installed in your machine,
so go to this particular location. So go to this uh this pc where you can see all the drives in your
computer. Go to the c drive where generally we we have the program files installed software is installed
go to the program files.
If you have installed the MySQL 64-bit version, go to the program files, then find this MySQL folder. In
the MySQL folder, you have to select this MySQL server, some version, whatever it can be. And inside
this MySQL server folder, you will find this bin folder.
Inside the bin folder, you will see this MySQL application. If you see this MySQL application, then you
are at the perfect path. Now here, type cmd. Select this path. You have to select the path like this. So, on
the top of, after selecting this path, you have to type CMD. So I have to select the path and then type
cmd there and enter. Okay. When I select this path, type cmd and then press enter, I'll get this
command prompt open and the default location, okay, that will be selected will be c program files,
MySQL, MySQL server, whatever the path is there, that will be coming.
If I directly open this command prompt like this, okay, then you see the default path is see users are on
arunium But if I want to have the path like this, see program files, MySQL, MySQL server bin, then I have
to go to this particular location, select the complete path, type CMD and press enter. You'll get this path
here. Okay. So these are shortcuts for doing so. Now here, from here, I need to run this MySQL. So, so
MySQL application I have to run. So I have to say MySQL. I have to type MySQL here, followed by. So in
order to run this application, I have to provide the username. Okay. So hyphen U. iPhone U stands for
username. The username that I have given while installing this MySQL DB software in my machine as
part of the earlier videos is root.
I specified the root username for the MySQL server software. While installing the MySQL DB software, I
specified the root as a username for the MySQL server. So, username is root and password, iPhone P I
have to say. I should not enter the password here. I simply have to say iPhone P then enter. then it will
ask for the password, guys. Okay? Only give up to here mysql-u root root is a username and hyphen p is
password. But you don't have to enter the password here. When you press enter, it will ask for the
password. Here the password for the mysql server is again root okay this all these things like username
root and password root, all those things have given as part of the previous videos okay so you watch the
previous videos.
Press enter. Then you see we got connected to the mysql server here. Now in this mysql server we have
i have if i if you have to find out the different databases available in this mysql server what is the sql
command for finding the different databases in the mysql server so databases you have to say show
databases and press enter so all the dbs which are there in this mysql server will be displayed here and
out of all these dbs i would like to sell select this mysql okay i have created this mysql db as part of
previous videos okay so now i have to select that mysql db created by me. Use MySQL is a sql statement
for selecting the one of the db out of all the available dbs in this particular mysql server.
i mean uh the db gets uh sorry i should not be saying mysql here. I have to say use QFox, okay? QFox is
the db that i created as part of the previous videos. I'm going to select the qfox DB. So database has
been changed to qfox uh okay so now qfox is selected. so after selecting this QFox, I would like to find
out what are the existing tables, okay? What are the tables that are there that are created inside this
qfox database? So for that, we have a command known as show tables. Show tables. So inside this qfox
database of this mysql server, we have the three different tables, EMP1, EMP2, mp3 EMP3 table i
created as part of the previous video.
So similarly, I can create one more table you have to create, what is the sql command? Create table
EMP4, okay? EMP4. int ID, ID as int, name as varchar, okay, varchar. Like this i can give. So the table got
created, but no records are available. If I say select star from EMP4, no records will be displayed, empty
records, okay? But if i try to insert some records, insert into emp4 values, values as one comma, okay,
Suresh. Done. One row got inserted. Another row. Insert into emp4 values as two comma nourish Okay.
nourish Another record got inserted. Insert into emp4 values three comma Alice. Like that you can insert
as many records as you want now if after inserting some records if i say select star from emp4
i'll get the table columns, ID name. Under that, we'll see the records. Three records are there, right?
Whatever the records are inserted, that will become like this guys we can perform any number of
operations on the tables. you can create new tables. We can delete the tables. We can update the
tables, alter the tables. you can do all the things from this command line, okay? Windows default
command line. We can do that okay so guys uh this how we can use default windows command prompt,
okay? command prompt for connecting to the mysql server and thereby performing different sql
operations on the tables or objects of the databases of this mysql server so that's it guys thank you bye
In this video session, I am going to explain about the different types of sql statements.
So in this video session, I am going to explain about statement types. There are several SQL statements
and all these SQL statements can be categorized into different types. At a high level, the SQL statements
can be categorized into these five types. What are they? DQL. DQL means here I will be writing what is
DQL. DQL means data query language. Okay. DQL means data query language. Then we have DML. Then
DML stands for data manipulation language. DQL, DML. Okay. These are so far two two types of sql
statements. Now we have DDL. DDL means data definition language data definition language now we
have TCL transaction control language and we have DCL okay data
control language. Like this, there are different types of SQL statements. That is DQL, DML, DDL, TCL, DCL.
So DQL stands for data query language. DML stands for data manipulation language. DDL stands for data
definition language. TCL stands for transaction control language and DCL stands for data control
language. So all the SQL statements can be categorized into these five statement types. Any of these
categories. So what are the different statements fall into the DQL? What are the different statements
fall into the DML? Let me give you some examples. So here we have the SQL statement types
categorized into five types. That is DQL, DML, DDL, TCL, and DCL, right? Under data query language, we
have the select SQL statement. You know about select, right?
For retrieving the records from the tables, we use select star from select column name from table like
that, okay? That is select statement, which falls into the data query language category. Coming to data
manipulation language category, we have the SQL statements like insert data into the table, update the
data in the table, delete the data from the table. These are like manipulation things. These three
statements will fall into the data manipulation language. Coming to ADL, data definition language. Using
this, we can create objects in the database. You can create tables, you can create indexes. Like that, we
can create a lot of things. At the same time, we can completely delete the tables. Using the drop
statement, we can delete those tables and all the stuff.
We can modify the objects. Modify the objects like modify the tables, etc. By adding more columns or
deleting a column. That is like alter. Then truncate. We also have the truncate, which also does a kind of
deletion kind of thing. Now we have TCL. Next category of SQL statement types is TCL. Tram section
control language. Under this TCL, we have the SQL statements like commit and rollback. Commit for
permanent saving and rollback. If not permanently saved, you can rollback to the previous state of the
data. So previous state of the objects. That is TCL. All these statements are explained as part of the
previous videos. In the previous videos of SQL, in this video series, I explained how to use select, how to
use insert, update, delete, create, drop, alter, truncate, commit, rollback.
Now the last category is DCL. DCL stands for data control language.
And under DCL, we have this grant and revoke. These are admin level permissions, right? If you want to
give some permission to the user to perform these operations, okay, you can grant. And if you want to
remove the permissions of the user for performing any of this kind of operations,
then you can use revoke. Till now, I have not explained how to use grant SQL statement or how to use
revoke SQL statement. I'll be explaining more about this grant and revoke SQL statements in the next
video session. In the next video session, I'm going to practically demonstrate to you how to use grant
and revoke, how to grant permissions to the user for performing this kind of operations on the table,
and how to remove the permissions of the user from performing this kind of operations.
These two SQL statements I'm going to explain after this session. That is, in the next video session, I'm
going to cover that. so guys, this is all about the different types of SQL statements we have and under
different type of SQL statements, what are the different SQL statements we have? Okay. So that's it
guys. See you in the next video session. Thank you. Bye.
Hello everyone. Welcome to part 90 of SQL for beginner series. In this video session, I am going to
explain and practically demonstrate on how to use grant and revoke SQL statements. so in this video
session i am going to explain and practically demonstrate how to use grant and revoke sql statements.
These are two sql statements, guys. These two sql statements falls under the, which category of
statement types?
DCL category. DCL stands for data control language, okay? DCL stands for data control language. In the
previous video, I explained there are different SQL statement types. All the SQL statements can be
categorized into different types. That is DQL, DML, DDL, DCL and DCL. And this grant and revoke SQL
statements falls under the DCL category of this SQL statement types. In this video session, I am going to
explain and practically demonstrate these two SQL statements that is grant and revoke. So before I
practically demonstrate these two statements for you, you need to understand one more thing. That is,
in my machine, we have this mysql server. In my machine, I have this mysql server available. Okay?
Already available. As part of the previous video, okay?
As part of the previous video, I explained how to install, okay? How to install mysql db software in my
machine. When I explain this how to install mysql db software, automatically you will get this mysql
server available in your machine. Okay? When you install this mysql db software, you will automatically
get the mysql server. Fine? And, while installing this mysql db software, you need to create a username.
You need to provide the username and password, okay, during this installation and configuration of this
mysql db software. You will be asked to provide the username of a root, okay, root user and password of
the root user. So, to, even i have given the username as root and password as root to the the root user.
What is the root user? This is a mandatory user, case okay. Root user is a super user super user in order
to create this, in order to install this mysql db software while installing, you will be asked to provide this
username and password, okay? That is root username and password. So I gave the root username as
root and password as root. So this user is required for connecting to the mysql server. Otherwise, you
will not have any users for connecting to the mysql server. So while installing this mysql db software,
okay, you will be asked to provide the username and password for this root user. Okay, that is root i
gave you can give any any username and any password, guys. We generally give username as root and
password as root.
Fine, this is a super user. What is super user? This root user is super user means he has all the
permissions. He has the permissions in such a way that he can manage other users also, okay? He can do
all the admin related stuff, okay? He has a high level permissions to do a lot of stuff. And at same time,
he can manage other users, okay? He can give the permissions to other users. You can take away the
permissions from other users. Such kind of things also the root user can do. So this username root and
password root is already available. Let me show you. So open Workbench. So how do you generally
connect to the mysql server? With MySQL server, when you install MySQL, DB software in your machine,
apart from that server, you will also get the Workbench.
Okay, Workbench is a client. Using this client, we can connect to the server. Open this. Then you click on
this Workbench. So and click on this. So here using the root credentials, root user credentials, username
is root and password is also root. Using that credentials of the root user or super user, you are getting
connected to the MySQL server. This is the client, MySQL workbench is the client and you are
connecting to the MySQL server by giving the root user's username and password. When I do that, you
will get connected. So apart from this root user, we don't have any other users. So you just go to the
server. Okay. And user sign privileges. Here we have root user. So apart from this root user, if you want
to have more users, you can actually create them here.
Okay. Click on add account. When you say add account. So here you have to give the username as, let's
say i will give the username as user1 and some password you have to give. Let me give the password as
QFox. Okay. Q is capital here and say dollar one, two, three. You can give anything. I'm just giving this
one uh q a fox dollar one, two, three. Okay. And then say apply. So another user got created that user
one. So here, apart from the root user, having the username and password as a root root, and i have
created another user. Another user has been created. This user has a username as user one. User one is
a username and password is qa fox dollar one, two, three.
This is in, in my machine you can, you can create such kind of users on your wish. and again, I will create
another user. That is, two users i am creating, guys. Okay. User two. QFox dollar one, two, three. So, two
users i would like to create. Second user i have to create here. So, again, add account. Here, again, user
two. uh again i'm giving the same password for this user also. Okay. So, okay. I just gave that and say
apply. So, two users got created. User one and user two. Now, now tell me, now we have three users,
right? One is a root user that is super user. Other than root user, we now have the user one and user
two for x you can use any of this user for connecting to the mysql server.
Right? You can, you can connect to the mysql server either using the super user that is root user that is
using the username root and root or you can also connect to the mysql server by using the credentials of
this user one or user two. That is also possible. But here, now, Using which user we are currently
connected to the MySQL server? Using the root user. But how to connect to the MySQL server using
another user? Let's say I would like to connect to this MySQL server using user 1. So for that, I will try to
close and restart Workbench. So when you do so, so you should not select this one. Instead, go to this
database and say connect to database. Now, this one or EES.
Here, username is root. Change this to user one okay user one user one and uh click on OK. Now you'll
get this connect to MySQL, but username is user one password is what guys qfox one uh qfox dollar one
two three is a password for this user user okay now this time, I got connected to the mysql server okay
mysql server using using user one but do you see any databases here no is no database is there here,
right? This particular user doesn't have access to any of the databases in the mysql server. What's the
problem? The problem is he doesn't have any privileges
okay yeah we have to give the access guys okay we have to give his uh give him we have to grant him
some permissions so that he can work on some databases.
Who can grant him the permissions to work on the databases to this particular user? The root user has
to do. So again, let's connect to the mysql server using the root user.
that is workbench again and now this time connect with the root user for root say ok so here i would
like to give the i would like to grant the user one to access this qfox database. So for that i will say use
QFox. okay so as root user i am typing use qfox so that i can select this qfox database now. To. Now I'm
going to grant some permissions to a particular user for this, for accessing this database. Only like, let's
see what we can do is I would like to only grant one of the table, only EMP1 table under this QFhouse
database.
I'm going to grant permissions. Okay. So that the user one can only work with this EMP1 table. All the
other tables of this database cannot be accessed. So something like that I'm going to do. The comment
here is grant which permissions you want to give. Let's say I would like to give the grant the permissions
of select the user one. This user one can only use this select command. Okay. Select SQL statement on
this particular emp1 table grant select on which table emp1 table okay i am granting the permissions,
which permission select permissions on which table emp1 table to which user to which user to user one
to user one i am granting the permission. If I run this, you see grant select on EMP1 to user1.
So now the user1 got permissions to perform select operations to run the select SQL queries on the
EMP1 table only. Let's see that whether the user1 got that. So how can we find out? We have to again
connect to the workbench. Again restart the workbench and this time again connect with the user1
credentials. Go to database, connect to database. and here, instead of root, you have to specify user one
and say okay and it will ask for the password of the user one i'll give the password as q a fox dollar one
two three
and say okay when i do so, now i got connected to this mysql server using the user one credentials and
only one database is displayed, qfx Under that, only one table will be there, guys.
Only emp1 table. This particular user one has the access to perform select operations only so now Now
let's say select, select star from EMP1 if I run this. Okay. So first I have to select the database, right?
Without selecting the database, you cannot do any operations in MySQL. So use QFox. Okay, this
database you have to select.
After selecting, you can perform operations on the table. Now say select star from EMP1. You see, I'm
able to retrieve the records from the EMP1 table. Fine.
Can I insert the records? Let's try this. Insert into EMP1 values as some 9 comma Kiran. 9 comma Kiran.
So I will get an error guys because this permission of inserting the records into this particular table for
this user 1 is not there.
Okay. Run this. You will get an error saying that permission. So command denied to insert command
denied to user. That means this particular user doesn't have user 1 doesn't have permissions to insert
records into table. You can only do what? You can only retrieve the records. Okay? So, so how come, like
what we can do? What we can do if you want to insert? If the user one has to, if you have to give the
permissions to the user one, what we have to do? Again, we have to connect to the mysql server using
root. Okay? So, as root user, this is our username is root and password is root. As root user or super
user, you will be connecting to the mysql server and this time,
So, you will grant more permissions. Grant, select, comma, insert, like that you have to provide. We'll
come to that again, okay? We'll come to that again. So, yeah, we can do that. For now, only grant two
permissions. Select, comma, insert on EMP1. Let's do this first. After that, I'll go to other one so user one
this time i'm granting two permissions. That is, not only retrieving the records, User1 not only can use
the SELECT statement but also you can insert the records using the INSERT SQL statement. So run this.
Now what happened here? You have to select the database again guys. Use QFox and now run this. This
will work now. So we granted two permissions. Not only SELECT but also INSERT. Now again connect to
the workbench and connect to the MySQL server as User1.
and let's see whether this user one got the permissions or not. So user one, say ok and give the
password as qfox$123 and say ok Now, again we have to say use qfox. Use qfox. Run this. And we got
only one table. because only user one has only one permissions to access this emp1 table now if you say
select star from emp1 select star from emp1 run this you can retrieve the records at same time you can
insert the records this time you this time the user one got the permissions to even insert the records
insert into emp1 values as some nine comma kiran if i give that like this okay this will work this time it
will work earlier it has not worked.
You see? Now again say select star from emp will get four records. That means i'm not able, I'm not only
able to, I'm not only able to retrieve the records but also able to insert the records because the root user
has granted the user one with the permissions of, with the permissions of uh retrieving the records
using select statements and inserting the records using the insert now let's remove permissions. Okay?
Now let's remove some permissions. How to revoke the permissions? in order to remove the
permissions for the user one again we need to connect to the mysql server using the root user okay as
root user again we have to connect guys uh by connecting to the root uh to the mysql server as root
user now you can revoke the permissions how to revoke how to remove the permissions you have to say
revoke this second sql statement guys okay in this video session i told you like i'm going to explain two
sql statements one is grant and revoke now i'm going to explain about revoke which is generally used for
removing the permissions for that particular user
revoke only insert i'm going to revoke this uh i will revoke both things what's the matter revoke select
insert on emp1 to not to from from you have to say okay in case of revoke we have to use from revoke
this both permissions that is select and insert uh for uh on which table emp1 table from which user user
one i'm taking back the Permissions. Both the permissions that this user one has for retrieving the
records using select statements, inserting the records using the insert into statements, right? These two
permissions, I am taking it back. Root user is taking back these permissions. Again, we have the same
mistake we are doing use qfox you have to say. Then only you can perform these operations.
Run this. You see, both the permissions got revoked or removed for the user one. If you connect as a
user one okay you you connect to the mysql server as the user one using the mysql workbench uh like
this, and here user one you have to say user one and say okay, and give the password here fox dollar
one two three and say okay okay uh you see, all the permissions got vanished. That means now the user
one doesn't have any access to any of the tables uh for performing anything, okay? So again, go back.
We can give a lot of permissions. There are a lot of variety of permissions we can give to the users. That
is, we can say grant different permissions like select insert.
Not only select insert, we can say create permission, delete permission, draw permission, update
permission, alter permission. All these permissions you can give to the users. At the same time, you can
give all permissions to the multiple users also. This much flexible this particular statement is. So, let's say
i will connect to the root user workbench. Workbench. I'll connect as root user okay root say okay okay i
gonna connect it as a root user and i'm trying to use qfox database and i would like to give multiple
permissions to multiple users in a single statement. Grant which permissions i would like to give? I
would like to give select permission. I would like to give insert permission. Then update permission, alter
permission. Create permission.
Okay, drop permission. Like this, different permissions i am going to give. And delete permission. So on
which, for which table? On EMP1 table. Okay, EMP1 table. To which user to user1 and also user2 For
two users, I am giving the permissions. I'm granting the permissions of selecting, inserting, updating,
altering, creating, dropping, and deleting the things on this particular table for these two users, not one
user this time, two users. This much flexible this grant statement can be having. So when I run this, all
these permissions have been granted to not only user one, but also user two. Both user one and user
two can perform this type of operations on EMP1 table. So similarly, we can use revoke also. okay again
rework if you want to revoke if you don't want to revoke all the permissions you can remove.
For example, I would i don't want to revoke the select okay remaining permissions. I would like to
revoke that is a insert, update, alter, create, drop, delete. I would like to remove for the this particular
users. So on emp one. two I would i would like to revoke this uh remaining permissions on emp table.
For these both users. So just copy paste this. We have to say from guys here. We have to say from. In
case of revoke, we have to give from. In case of grant, we have to give to. So that is the difference. Run
this. So all these permissions except the select permission got revoked for this both users. Like this guys,
we can use grant and revoke SQL statements.
Who will be using this grant and revoke SQL statements? It will be used by the root user. Root user will
be using this grant and revoke SQL statements. granting the permissions to the other users or revoking
the or removing the permissions from other users so guys this is all about the grant and revoke SQL
statements thank you guys bye
hello everyone welcome to part 91 of SQL for beginner series. In this video session, I am going to explain
and practically demonstrate about temporary tables. So, in this video session, I am going to explain and
demonstrate on how to use temporary tables fine so why are this temporary tables needed why we
have to create the temporary tables in sql okay the reason here is the reason here is there may be some
situations where there may be there may be some situations where the application okay the application
has to
create a table for a purpose. Okay? For a purpose, the application has to create a table. And thereafter,
thereafter, using the table, it has to delete it. After completing the usage of the table, it has to delete it.
So this is where the temporary tables are required. Is it possible to create the temporary tables in
MySQL? Yes, guys. Using the sql statements, we can create the temporary tables in MySQL. And they
only exist till the session exists. Let me practically show you how they work. Fine. So here, I'm going to
use MySQL Workbench client for connecting to the MySQL server. Already it got connected. Now, this
MySQL server has four DBs. QFox, Succulas is Word. This is created by me, whereas these are, this came
by default with MySQL server.
Now, I will choose one of the databases here. Let me choose QFox. So how to select this? Use QFox. This
is the command. This is the SQL statement which we have to use for selecting the database. Why we
have to select the database? In order to work with the tables under this database, we have to first select
the database. So after selecting the database, now the database got selected. Now, whatever the tables
that are displayed here, EMP1, EMP2, EMP3, EMP4, whatever it is, EMP, ER, all these tables are
permanent tables. So, even though you close this workbench and again launch the workbench and
connect to MySQL server again, these tables will exist. But if you create the temporary tables, they will
exist only until I close this MySQL workbench.
Again, if I try to launch this MySQL workbench, you will not see the temporary tables. Okay. So, let me
create a normal table. Okay. First, how to create a normal table, guys? Create table. Table name. Right. I
will say normal table. i'll give normal table. Okay. This is a normal it's not a temporary table. It's a normal
table. And here i will say id int name where care of 15. So this is a normal table guys. The name of the
table is also normal table. Okay. Just for the reference i kept that name as normal table. So run this. You
see here the table got created. Right. And if you refresh here the normal table. Okay. Normal table got
created under the tables of this qfos database.
But what if i create a temporary table? Will it be saved here? No, guys. Okay? You'll see that. If I say,
how to create a temporary table? Everything is same. Okay? Everything is same like this. But only
difference is here, create temporary. You have to have the temporary keyword. Okay? Only this is
different. Create temporary table. Temp table. Okay? Temp table. Name I am giving the table name as
temp table. You can give any name. I'm just giving temp table. ID int name where care of 15. Okay,
where care of 15. If I give something like this. So here temp table with the name temp table, a
temporary table will be created. So what is the difference between this normal table and temporary
table?
Only one thing. There is temporary keyword added to this particular statement. That's the only
difference. When you add the temporary keyword to the create table statement, it will create a
temporary table. Run this. You see the temporary table also got created. If you refresh here, you will not
see the temporary table here, guys. Okay? You see this temp table name is not there any of these tables.
So, it cannot be saved. This is just for temporary purpose. It cannot be saved into the, okay, final list of
the tables in this database so we can can we insert any records into this temporary table? Yes, guys. We
can insert that. Okay? We can insert the records. How to insert? Insert into. Insert into. temp table
values, same thing, okay?
The same way you insert the records into the table, the same way you can insert the records into the
temporary table. Fine, here i will say one okay then we have insert into insert into temp table values as
two one insert into temp table values as three. Like this three records i am trying to insert. If I run this,
three records will be inserted into this temporary table that is with the name temp table. If I say select
star from temp table, okay? Table name that is temp table, temporary table name temp table. If I say
like this, it will give me the results, okay? Until we are in this session we this particular things will work
guys Now, what I will do is, I will simply, okay, I will simply, I will do one more thing.
I will also insert some records into the normal table also. This is a normal table here. Here also, I will try
to insert records. So, I will change this to normal, normal table, okay. So, normal table also, I am trying
to insert the records. So, what is the difference between this normal table and temporary table, we will
get to know. Run this. So, records got inserted. How to find them? Select star from normal table. So,
normal table is a normal table. So, which will be saved. Okay. It will be saved. But coming to temporary
table, it's going to disappear. Okay. It's going to disappear. It will only exist until this session is session of
the work mysql workbench exists now here here if i say select start from normal table, you will get the
records.
Okay. Now, guys, temp table, we are getting the records. Normal table, we are getting the records. Fine.
Now, let me close it. Now, let's relaunch the workbench. Now, let's relaunch the workbench. When I try
to relaunch the workbench, MySQL workbench will open. Let's connect to the MySQL server. Let me give
the password root which I configured for MySQL server in one of the previous videos. So, say okay.
Okay, done. Now, guys, here normal table is there. If I say select star from normal table, you will get the
Sorry, first you have to say use QFox. First select the database, then perform operations. If you say select
star from normal table, you'll get the records. You'll get the records. Because this is a normal table.
It's not a temporary table. It will exist even after the session of the MySQL workbench closes, expires.
Now, coming to the second one, that is temp table. This is a temporary table. Now, if I say select star
from temp table, will I get these records? You'll not get the records, guys. it will say that the table is the
name table doesn't exist. That means it's not there. It got deleted. When the session of this mysql
workbench has ended, okay, this table got automatically deleted. It is because it is a temporary table it
will not be it will not be saved for future use. It's only for that time purpose, okay? Even though we
created the temporary table in my in the previous session of this mysql workbench, now after i restart
this mysql workbench, now the table is not there.
Okay? Because it is a temporary table. So guys, this is all about the temporary table. Okay? Hope you
understood. Thank you guys. Bye.
Hello everyone. Welcome to part 92 of sql for beginner series. In this video session, I am going to explain
and practically demonstrate on how to use different sql statements like show columns, show indexes,
show privileges, and show grants.
so in this video session I am going to cover four different SQL statements like show columns show
indexes so privileges and show grants these are the four different SQL statements I am going to cover in
this video session and apart from this for show statements we have two other show statements which I
have already covered as part of the previous videos we are
show databases.
I already covered, I already covered this show databases as part of one of the previous videos also show
tables this also i covered as part of the previous videos. Now, in this video session, I am going to cover
this four different, the four other different, okay, show statements, that is show columns, show indexes,
show privileges, show grants. Now, let me practically demonstrate. Fine. So, here we have four DBs. uh
i'm going to select this QFox, okay? I'm going to select this qfox so use qfox database or before doing so,
before doing so, let me revise this. Show databases, okay? You can say show databases here. What are
the different databases we have in this mysql server, okay? This particular statement will get us.
So there are this different number of databases Okay, inbuilt databases and external database these
four are something we can use, whereas internal databases are there here. As you can see, QFox is there
here and secular database is here, this is here and world is here. Other things are like internal databases,
that's fine. So out of this uh four databases, I would like to use the first database that is QFox. Okay, in
order to work with or practically demonstrate in this video session, I'm going to select this, one of the
databases out of this four databases. So here, Show statement can be used for finding all the databases
that are there in the MySQL server. After that, using the use statement, you can select a particular
database.
Now, this QFox database, out of all the remaining databases of this MySQL server, got selected and we
are now free to perform any operations on any of these tables of this QFox database. After this, in this
QFox database, I would like to know how many tables are there. What are the different tables available
in this QFox database? For that, again, we have to use a similar type of show statement which says show
tables. Okay, show tables. When I run this, all the tables which are available in this qfox database will be
displayed here. Tables in qfox database will be displayed here. So like this guys, in the previous videos, I
already explained how to use show databases and show tables. Now in this video session, I'm going to
explain the other four show statements.
Okay, there are more show statements guys. Okay, not only the six, but there are many things. For
example, if you go here into the google and search for MySQL, show show statements okay mysql show
or something, you just type here, there. Okay, show sql statements, show statements. Okay, statement
Yeah, this is a one. MySQL show, just go to this URL. You will see a lot of sql statements, okay? There are
a lot of statements, guys. so binary logs so collation show column show create show events like that,
many things are there. but we generally don't use all those things, okay? We use some common things
like uh here we have show tables, okay? We'll be using show tables, show indexes okay show columns
show databases all these are the general things that are used, okay?
These are the general things that are used. Other than that, we don't use any other things. So here, I
already explained how to use show database, show tables. Coming to this one, so there are many
shows, show selection statements right uh there are many show sql query statements. But but this four
will be enough or this six will be enough, guys, okay? Learning this six sql statements related to show will
be enough. You don't have to learn more, okay? You don't have to learn more. Only this six will be
enough, guys. So what we can do here is uh the six sql statements, okay? the six sql statements uh let
me practically demonstrate. I already demonstrated these two. Now I'm going to demonstrate the
remaining four so sql statements so now we got the tables.
Now in this emp1 table, I would like to find all the columns. Okay? So for that, for that, what i have what
i have to say show columns show columns from show columns from which table, EMP1 table. I would
like to find or list down all the columns from this emp table. Like this show columns statement can be
used run this so here this emp1 table in qfox has, how many columns? Only two columns. That is id and
name so id column name column so two with the details of these columns got displayed here. Now, now
there are some, there are some tables guys which have some indexes. Here you see this particular table
emp4 doesn't have an index. You cannot expand this.
But there are some databases here like this. Expand them. City. You see the city table under the world
database has this columns. At same time indexes are also there. Okay. So now, let's uh let's uh move to
this world database by saying use world database. So this world database will be selected first. After the
world database got selected, you can perform operations on any table of this world database. So here, I
would like to find out all the indexes which are there for this particular table city. For that, you have the
show statement saying show indexes from which table city, okay? From city table of world database.
Show indexes from city. When you run this, all the indexes we have for this city table will be displayed
here with a key name, primary, and other name of the index is country code.
Let's see that, whether that city table has these indexes or not. I already explained about indexes as part
of the previous videos, guys. You can refer that video to get an idea of what exactly the indexes are. You
see, this particular city table has these columns, okay? And at the same time, it has these two indexes.
So, using show indexes, we can find the indexes of this city table. Now, one more thing. Now go back. I
can say use QFox. Let's go back to the previous database that is QFox. So here, if you remember, in one
of the previous sessions, before going there, that's fine. Before going there, let me explain another show
statement. That is nothing but show privileges. If I run this, what this particular SQL statement will result
in?
So, whatever the privileges that my sequel okay can provide, all this, okay, this is a complete list of
privileges that we can assign to a particular user, case okay, in my sequel in my sequel this is a list of
privileges in my sequel okay this is a list of privileges in my sequel if you want to find out all the
privileges that are there in my sequel okay then you can find detailed explanations, guys. If I say show
privileges here alter alter privileges there. What is the purpose of this? To alter the table. Create. To
create the databases, tables, indexes, and other stuff, okay? So here, drop. For dropping, that is deleting
the databases, tables. Delete. Deleting the tables. And a lot of a lot of privileges all the commands and
all those things in sql will be displayed here, as you can see here, right? So a lot of privileges came here.
so these privileges, you can assign to other users. In the previous video, I explained, if you go to the
server and user sign privileges, you can create any number of users here, okay? For this mysql server, by
default, we have, when you configure and install this mysql server, you have to create this root
username uh with the root password i gave right similarly uh this is the important one, okay?
This is a default user or root user or super user who has all the privileges. But apart from this root super
user, you can create other users also, okay? Other users also. By connecting to this mysql server as a
super user, root user, okay? In the mysql server, we can create more users by going from server user
privileges and coming here. And here we have add account. I explained this, how to do this in the
previous video, guys, okay? So I don't have to explain again, fine? So like this, we can create more users
here. So this, these different users, Let's say in the previous videos we created these two users, user1
and user2. As part of explaining this grant and revoke related SQL statements, I created this user1 and
user2 as part of the previous videos.
Now we have this user1 and user2. Now I would like to find out what permissions or what privileges that
this particular user1 is granted with. And what privileges that this user2 is granted with. I would like to
find out. So how to find out? how to find out show grants okay show grants for give one user name guys
okay user one for user one what are the privileges granted? For that, you have to run this statement. so
grants for user one. If you run this, all the privileges that are, all the privileges granted to this user one
will be displayed here. You see, this particular user one is granted to use This privileges like select,
insert, update, delete, create, drop, alter. On which table?
On EMP1 table of which database? QFox database. Only this EMP1 table of QFox database, this
particular user, user1 is granted with all these different permissions. Like you can perform select
operation on this EMP1 table of QFox database. Insertion, you can insert the data into this EMP1 table
like that. Similarly, other user, that is user2, is also granted with different permissions. In order to find
out the privileges for user 2, we have to again run this statement, show grants for user 2. When you run
this, all the privileges that got granted to user 2 will be displayed. Only user 2 is granted to perform
select privilege on EMP1 table of QFox database. Only one privilege is there, that is select privilege,
whereas user 1 has
many privileges like select, insert, update. Whereas user 2 only has a single privilege. That is select
privilege. The table is same. The database is same. Okay. So guys, this is how we can use the different
show statements in SQL. That is show columns, show indexes, show privileges, and show grand
statements. So hope guys you understood this four different show sql statements. So that's it guys.
Thank you. Bye.
Hello everyone, welcome to part 94 of SQL for beginner series. In this video session, I am going to
explain and practically demonstrate on how to insert null values into the tables. So in this video session,
I am going to explain and practically demonstrate how to insert null values, how to insert null values into
the tables.
So there are two ways. There are two ways in which we can insert null values into the tables. So one is
direct way guys. There is a direct way and other way is no value. If you don't provide any value it will be
null. Direct way is when you directly insert null value. Okay. When you directly insert null value, it is a
direct way. When you don't insert any value, that is also nothing but null. Okay. It's an indirect way, but
when you don't insert anything, it will become a null. So let me practically demonstrate how to insert
null values into the tables now. So let's go to this uh mysql workbench which got connected to this
mysql server. As you can see, there are four DBs.
I would like to work with this qfox DB, which i created as part of the previous videos. So use QFox. Run
this. The QFox database got selected. Now, we can perform operations on any tables or anything. Any
operations we can perform on this QFox database now. Okay. As we have selected it. Now, what I would
like to do is I would like to clear all these tables. I would like to remove all these tables. Okay. Drop
tables. I am just dropping so that I can freshly create a new table and work on it. Now, guys, let us create
a new table. How to create a table? Create table. Okay. EMP1. id as int data type and name as varchar
data type. So run this.
When you run this, a table will be created inside this qfox database with this name EMP1. Refresh this.
So this table emp1 is going to have two columns that is id and name. fine two columns are there, ID and
name. Now into this table, okay into this table i would like to insert some null values how to insert insert
into emp1 values as one comma this time i'm not inserting any null values okay i'm just providing two
values so here two columns are there that is id and name are there and into these two columns i'm
inserting values real values i'm inserting so insert it it got inserted if i say select star from EMP1. The first
record will be displayed with both the values.
That is 1 and R1. This time, I would like to insert some null values. Insert into EMP1 values as 2 comma
null. Here, I am manually inserting null. Directly inserting null, guys. This is a direct way. If you don't
want to insert any value, if you directly provide null, it will take it, guys. This will work. You see, this got
inserted. Now, if I say select star from EMB1, you see in case of the second record, in place of the name,
we have manually inserted null, directly inserted null. This is the way of inserting null into the tables,
table columns. Now, another way of inserting null is don't provide any value. If you don't provide any
value, automatically null value will be inserted.
You don't have to manually insert null into this table records. If you don't insert any values into one of
this record columns, then automatically null will be inserted. For that, we have to write something like
this emp1 i would like to only insert okay i would like to only insert name okay i am not going to insert
ID. Say values as, here i am giving term so in place of this i am not i am not inserting anything into the id
column. Only name column i am inserting. Here I am specifically specifying that in this emp1 table, I am
going to insert the values only into the name column. not into the id column i am not providing id okay
that's the reason only name i am providing if i run this a null variable will be a null value will be inserted
into the id column okay so select star from emp1 you see under the third record as i have not inserted
any id okay as i have not inserted any id value into this third record of this emp1 table instead of that id
null value got inserted okay and since i have inserted this down into this name
term got inserted. So this is how guys we can insert null values either direct way or indirect way. So
guys, hope you understood how to insert null values into the tables. So that's it guys. Thank you. Bye.
Part 94:Using trim() for Trimming The Corner Characters of the Specified Table Values
Hello everyone. Welcome to part 94 of sql for beginner series. In this video session, I am going to explain
and practically demonstrate on how to use trim function for trimming the corner table values.
So in this video session i am going to explain how to use stream function. How to use stream function for
trimming the, that is removing the corner characters. Corner characters of the provided table column
values. So in one of the previous videos, I explained about this stream function. and in that video, I
explained how to trim the spaces.
For example, in a particular column, okay, table column, is something like this, okay, like this. There is
some space, one space, two space, three space, four space, okay, there are some spaces here. Before
the arun text and after the arun text, there are some spaces. With such kind of text, if you trim, if you
use trim function, then it will convert this arun text having the spaces into normal Arun text. That is the
spaces which are there before the starting of the text and spaces which are there after the ending of the
text will be trimmed. That is they will be removed. So this will be converted to this one. This Arun having
spaces will be converted to normal Arun using the trim function.
So how to do that? I already explained as part of the previous videos. So in this video session I am going
to again use the same trim function but this time i am going to trim the corner characters of the
provided table column values. For example, if i am providing Arun, okay? If I am providing arun and if i
say trim, trim, that is a from Arun. Trim A from Arun. If I provide something like this, what will be the
result here if this particular arun text has any corner values like a they will be trimmed guys so here the
corner value is a so a will be removed and other side there is no a so nothing will happen so the result
will be run when you apply this stream a from arun a will be removed from the corners so this is how
guys we can use stream function for removing the corner characters of the provided table column
values let's take some more examples if i say if i say
what is that rana okay if i give something like rana if i say trim of a from rana what will happen in this
case what will happen guys in this case the corner character if there is any corner character like a in this
particular rana text that will be removed so on the left side corner there is r that means a is not the
corner so nothing will happen on the right side corner we have a So, A will be removed. So, what will be
the result after trimming? It will be run. Okay. A will be removed on the right side. Similarly, if I give
some text like Aruna. Okay. So, Aruna. Aruna has A in the beginning, A at the end. Corners are both As.
If I use trim function like this, trim A from Aruna. Okay. Trim A from Aruna if I use. So, what will happen?
In this case, in Aruna, A is in the corners. So, both the A's will be removed from the left corner and right
corner and result will be run. Result will be run. So, this is how guys stream function
can be used for removing the corner characters of the provided table column values. Here, I have not
provided any table column values. I just explained with a normal text. So, similarly, let us say there is a
table. There is a table having only one column. Let us say the table name is EMP1, EMP1 table name.
The column name is only named. There are several names in this table.
So the names like, names like Arun, warun Nandan, sarun Okay, like this some names are there. So in
this case, in this case, If I say trim, if I say trim function of character n from the column name is name,
right? Name. So it should not give like, it's like name, name column. Here name is a column. So trim n
character from name column from which table? From emp1 table. Like this if you have to give the
syntax. If you run something like this, what will happen is so this stream function, okay, this stream
function will remove the corner characters that is n from this name column. For example, Arun is there
in that corner character is n, right side. So the result will be Aru.
Similarly, here varun is there. Here the right side corner character is n. So n will be removed. So result
will be Varu, okay? Then Nandan is there in nandan the both the corner characters are n. Here n. here n,
left side, right side corners okay so ada will be the final value. So, n and n will be removed by this stream
they will be trimmed. In Tarun, the last letter is n, okay? The corner, right side, right side corner is n.
That will be trimmed, that is removed. So, the result will be taru okay? Like this, guys, okay? This is how,
when you apply the trim function okay to for removing the characters or trimming the characters from
the column values, it will be like this.
So, now, guys, let me explain, okay, practically how to use this trim function in the sql statements. So,
hope you understood the theoretical concepts here and i gave some examples, but let's take this all
these examples into the practical format now. Okay, so for that, we have to open the workbench. Let's
open the workbench, guys. The workbench will be opened. So, the workbench got opened guys so let's
connect to this mysql server. from this mysql workbench client the root is a password guys in one of the
previous videos i configured this mysql client to give root as a password okay so for mysql server i gave
the root username and root password to connect so fine now clear all this stuff let's say i'll also clear this
and so before doing any operations i would like to drop all these columns okay all these tables i would
like to delete all these tables i would like to work in a fresh manner
or this qfox database doesn't have any tables now. First, I will connect to this qfox database, guys, which
i created as part of one of the previous videos. How to how to connect use qfox okay uh how to select
this qfox database? You have to say use qfox and run this. The QFox database will be selected. After the
qfox database is selected, okay, now i need to create a table. How to create a table? Create table. So,
before creating a table, we'll do something, else okay? So, that is like uh What we can do is I will apply
the trim with direct text. We can do that. Without a table also we can work. So if I say trim of A from
Arun.
Like this we have to work. Put a semicolon. So here what is the thing guys? I have to say select guys.
Select. Select statement. Without select it will not work. Select trim of A from Arun. What will happen
guys? What will be the result? Can you guess it? Yes, this A character will be removed from the corners.
Here, on the left side corner of this particular Arun text, A is there. So, A will be removed. So, what will
be the result of this select statement? Select trim of A from Arun. The remaining run will be retrieved.
So, run this. So, RUN. A got removed from the left corner and remaining text got displayed here. Now,
select trim of A from Arun. So, what will be the result in this case?
Here in Rana, the right side character is A. Right corner character is A. So, A will be removed from the
right corner character. Remaining will be retrieved. Run this. So, ran. So, first three letters ran and last
corner got removed. Now, the third one is selected trim of A from Aruna. A from Aruna. So here Aruna
text. So in Aruna text, both the corners are A and A. A and A. So trim A from both the corners of Aruna.
So what will be remaining? RUN will be remaining. When I run this, you will get the result as RUN. Like
this guys, we can use trim on the direct text. Now let's apply the trim on the column, okay, table
columns. For that, let's create a table, create table, EMP1.
Only one column I'm creating in this table, that is name column. name where care of 15. Name where
care of 15. So run this. Create table EMP1. Name where care of 15. The table got created guys. Refresh
here. The table will appear here. And it has only one column. That is name column. Okay. Fine. Now let's
insert the records into the emp1 table en insert into EMP1. Values as. First value i will insert as Arun.
Okay. Now insert into. EMP1 values as Varun. Then insert into EMP1 values as Nandan. Nandan. That's
it. Let's insert this three records. Run this. Over here we can give another name instead of Varun. We
can give Naresh. So that all the examples will be covered. Run this.
the three records got inserted into the table. How to find all these records? I have to say select star from
EMP1. When I run this select star from EMP1, all the records from the mp1 table will be displayed here
like this. So here, a name column is there under that narration and then arun are there right that is arun
narration and then three three values are there. Now, let's apply select statement by saying trim off.
Select trim off, okay? n character, from which column? From which column? Only one column is there,
so name column. Name, from which table? EMP1 table, like this. So, N, N character, if it is available in
the values of this name column, in the corners of the values of this name column, then that n will be
removed.
That is here, N is there on the right side. Here, N is there on the both sides in and then here n is there on
the left side only. So all these corner Ns will be removed if available from the EMP1 table. If I run this,
once they are removed, they will be retrieved, okay? Like this. So ARU, instead of Naresh, ARESH,
instead of Arun, we got ARU because N got removed here. Here, the beginning N got removed. In case
of Nandan, the beginning and ending N got removed. So guys, this is a temporary change, right? Just for
retrieval purpose, it is there. But in the original table, the values will be like the same, okay? So, this is
only for getting the result by trimming.
Trimming and getting the results, guys. Okay? Nothing more than that. So, guys, this is how we have to
use trim function for trimming the corner characters of the specified table column values. Hope, guys,
you understood this session. Thank you, guys. Bye. Hello, everyone.
Welcome to part 95 of sql for beginner series. In this video session, I am going to explain and practically
demonstrate on how to use wildcards as normal characters. So in this video session i am going to explain
how to use wildcards as normal characters, okay? Normal characters. So in the previous videos, I
explained how to use wildcards in sql as part of MySQL. There are only two wildcards, okay? There are
only two major wildcards that you can use in mysql as part of sql statements.
In MySQL, there are only majorly two wildcards. What are they? One is underscore and other one is
percentile. Underscore means single. Percentile means many. Okay? If I say underscore run, here only
one one thing can be filled. Like earn. Okay? But if i say percentile N. Okay? Before N, multiple things can
come in in place of percentile. Wildcard, you can use aru or you can use var var u so four letters. Earlier,
three letters. Now, five letters so any number of any number of things can be used before N. Percentile
stands for multiple under stands for represents only single. So, this is what about the wildcards. I already
explained how to use wildcards in sql statements as part of MySQL. in the previous videos.
Now in this video session i am going to explain a practical situation where you may have to use wild
cards as normal characters. Okay? You have to use wild cards as normal characters. So what is that
situation and why we have to use wild cards as normal characters? Let me explain practically. So let's
switch to this mysql workbench. So it got connected to mysql server already and uh you see use QFox.
The QFox database got selected. and under that qfx we have this emp1 table. I already created this
emp1 table in a previous video, okay? So I am using the same emp1 table. So if i say select star from
EMP1, I got this results. Only one column that is name is there.
Under name column, we have these three records having the names as Arun, Naresh, Nandan, like this.
Now, let me insert one more record. Insert into emp1 where name is equal to, okay? where name is
equal to d i n e s h underscore okay d i n e s h underscore like this the name should be there so uh sorry
insert into emp1 values, I have to say and that's the mistake guys uh values uh here i have to give. So, a
lot of mistakes i did here. Let me correct. Insert into emp1 values have to give something like this d i n e
s h under like d i n e s underscore let's say. Okay. So let me try to insert this kind of value.
Okay. Insert into emp1 values d i n e s underscore now guys run this. This value will be added into the
table. So apart from arun naresh none then we have d i n e s underscore now if i say If I say select star
from, let us say my requirement is to only retrieve this DINES underscore. So if I say something like this,
select star from EMP1 where name is equal to or name like percentile underscore. So what do you think
will be the resultant value? Will I get Dinesh as I am expecting because it is ending with underscore?
DINES underscore. So, here percentile underscore I am saying. So, what will be the result guys? If I run
this select statement, what will be the result?
Will I be getting only Dinesh? Dinesh underscore or will I be getting all the values? I will be getting all the
values guys because percentile means A R U underscore wins single letter that is N. Here percentile N A
R E S underscore will stand for H. Like that everything will be coming guys. It is not only Dinesh
underscore but all the things will be coming. But if I would like to only retrieve this Dinesh underscore,
then I have to use this underscore as character here. Here underscore is a character in this particular
name. Dinesh underscore is not a wildcard here. It's a character. I have to use this underscore in this
select statement as an underscore only, but not the wildcard. So how to convert this wildcard into the
character?
For that, we have to use a default symbol. uh that is slash. This kind of slash. Okay. So kind of backward
slash. Percentile backward slash underscore. Okay. So this underscore wildcard will now will be
converted into normal character underscore. If you add this backslash before this underscore this
wildcard will be converted into character. Okay. This is this underscore is not a wildcard. This underscore
combined with this backward slash will become a will become what guys? It will become a character. So
this time, if you search this particular if you if you run this statement, you will only get dinesh
underscore. Percentile means anything. Last character should be underscore. So none of these three
records, first three records have the underscore at the end so that that thing will happen guys, okay?
Run this. You see this time you only got dinesh underscore because you are using this wildcard as a
character
here, okay? This particular text, of the names should end with underscore character so to represent that
wild card as a character we have to use this backward slash underscore then only it will work so similarly
similarly i don't want to use underscore for converting this wild card as a character okay instead i would
like to use dollar is it possible if i say percentile dollar underscore will this wild card will be converted
into character or not like the same way okay No case, it will not be converted. If I run this, you see no
results are coming. That means percentile, dollar is a character, underscore is a wildcard here.
I am not converting this wildcard into the character. Instead, there are two wildcards and in between
some character like dollar is there. But how to use this dollar in place of the backward slash to convert
this wildcard into the character? For that, we have to say escape, escape, the single quotes, say dollar.
Okay. Now in place of backward slash, you can now use dollar also. Now dollar will also will convert this
wildcard into the character okay because here you have here you have mentioned escape dollar. That
means this this underscore will now be converted into the normal character using this dollar symbol.
Instead of the backward slash, you can also use dollar here until and unless you specify this escape
dollar. Then only you can use that.
Okay. Then only it will convert. If you don't provide this escape dollar, it will not convert okay So, run
this. You see, Dinesh underscore. Here wildcard got connected into the character. Percentile means any
number of text before that underscore character. So, Dinesh, all percentile done, then underscore
character. Okay? Like that it got searched. Now, escape dollar means in place of backward slash, you are
using dollar. Okay? That's what is the meaning. So, like this, guys, we can, like this, guys, we can convert
the wildcards as normal characters when needed in the sql statements. Oh, guys, you understood this
session. Thank you, guys. Bye.
Hello, everyone. Welcome to part 96 of SQL for beginner series. In this video session, I am going to
explain about database objects.
So, what are database objects? What are database objects? The things that the things that we can
create under any database using the create statements in SQL are nothing but the database objects. So
let's say there is a database. Let's say there is a database. This is a symbol for database. Generally, we
represent the database symbol something like this. So, in database, we can create different things. What
are the different things that we can create under the database? We can create tables. We can create
tables. We can create views. We can create views. We can create indexes. we can create indexes. I. And
we can create stored procedures. And many more. Okay. The things, these are the things guys. Okay.
Example things that we can create and in the database.
That is table, views, indexes, stored procedures. Examples are tables, views, index, stored procedures.
procedures and etc. There can be any other things also. So these things are nothing but the terminology.
The terminology that we generally use for the things that we can create under the database is nothing
but database objects. So table is a database object. View is a database object. Index is a database object.
Sort procedure is a database object. The terminology here is database objects. Okay. We generally use
the terminology like database object so in order to call this table, table is a database object. Okay.
Views, view is a database object. Like that guys. Okay. So let me, so another part of the statement here
says that using the create statements in SQL, for creating the table, we use create statement.
For creating the views, we use create statement. For creating the index, we use in create statement. For
creating the stored procedures also we use create statement. Let's say let's go to this MySQL
workbench. There is some sample table. Let me drop it. I'll create a new one. QFox here is a database
like this. Here QFox is a database. Inside the QFox database we can create database objects using what?
Using create statements. Suppose under the qfox database if i have to create a table using what syntax
using what sql statement i will be creating a table create table okay table name emp1 id as int name as
varchar so like this if i give so here i have used create statement for creating the table with the name
emp1 run this so before running this
i don't have any tables here, but after running this, a table will be created under the database. Here,
EMP1 is a table object of qfox okay tables are nothing but objects of qfox database okay tables are
nothing but objects of databases so in under the QFox, we have table objects okay one one table object
is emp1 like similarly similarly for this table we can create index. so how to create create index index
name let's say id index, okay? On which table, EMP1, for which column, ID column. Like this, using the
create statement, we can create the index under the database for a particular table. So here, run this.
When I run this, this statement got executed and when you expand this particular table and refresh
here, you will get this index also, okay?
ID index. I created the ID index. So here, index is also an object of the database. Table is an object of
database. Index is an object of database. Okay. And similarly, we can create views. Okay. Under the
database, we can also create views. How to create? Create view EMP view. Okay. As select star from
EMP1 table. Okay. I'm just creating a view with the name EMPView using this EMP1 table under the
QFhouse database. So, run this. It got executed. When I refresh here, you see, I even got the EMPView.
Whatever the view I created, it got displayed here. Whatever the index I created, it got displayed here.
Whatever the table I created, it got displayed under the database here. Similarly, I can also create the
stored procedures.
Stored procedures. So here I can create stored procedures. They are like functions guys. So how to
create stored procedures? Create procedure. Procedure name. Like get all employees. EMP details. Let's
say I am just giving some function kind of name. So here I have to say begin and end. In between I will
write a SQL statement like select star from EMP1. You can write more statements also. Select ID from
EMP1. Select name from EMP1. Like this I can create multiple statements. But here I am getting some
error. So to avoid this error, as explained in one of the previous videos, I have to use delimiter. Delimiter
double slash. Then all the errors will be removed. so here after the end also you have to use the
delimiter.
Okay, whatever you define at the beginning of the procedure creation. So this is how we can create
procedure. This is how we can create views. This is how we can create index and this is how we can
create tables. So I explained all all these things in the previous videos already. Okay, how to create
tables, how to create indexes, how to create views and how to create procedures. Everything in detail i
explained as part
of the previous videos this okay the context of explaining these statements in this video session is to
state that, okay, if i run this, what will happen? So it got run, refresh, refresh. In stored procedure, we
got this uh stored procedure also, okay? So all these things are getting created under the database,
right?
This table is getting created under the database. This index is getting created under the database. This
view is getting created under the database and procedure also is getting created under the database. So
what are database objects? now understand the definition here. Okay. Whatever I written here. Okay.
The things that we can create under any database like tables, indexes, views, stored procedures. Okay.
Using what? Using create statements. Here I have used create statements. Create, create, create. For
everything i use create statement. Okay. Using the create statements in SQL. Okay. SQL statements. I
have used sql statements. That is create sql statements. Are nothing but the database objects. And we
generally use this database objects. as part of terminology, okay? So, to refer a table or view or index or
store procedures, we generally call them as database objects.
That is a terminology, guys, okay? So, guys, hope you understood what are the database objects. So,
that's it, guys. Thank you. Bye.
Hello, everyone. Welcome to part 97 of sql for beginner series. In this video session i am going to explain
on how to create a linux virtual machine. So in this video session, I am going to explain how to create a
linux virtual machine. So what is the purpose of creating this linux virtual machine in this video session?
The purpose is very simple. In order for me to explain or show you on how to, on how to install mysql db
software in a linux machine okay my linux machine the previous videos, I explained how to install mysql
db software in a windows machine the the operating system that is there in my laptop is Windows,
Windows 10.
So in the windows 10, how to install the MySQL, I already covered as part of the previous videos. Now, if
i have to explain you on how to install this mysql db software in a linux machine. Then what i need guys?
I need a, how to install my mysql db software in a linux machine. I need what? I need a linux operating
system machine, okay? But in my laptop, I have windows operating system, but i but i need a machine,
but i need a machine which has linux operating system installed. So, is there any way? I need to have
another machine, right? In my machine, already Windows 10 is there. But in order for me to explain on
how to install MySQL DB software in a Linux machine, I need another machine that is, which has Linux
operating system.
So, it's a very costly thing, right? So, even I don't have multiple machines with me, I only have this
Windows 10 operating system installed machine with me. Then still I want to show you how to create a
Linux operating system into a machine. so how this is possible? There is a possibility guys. There is a
possibility to create a virtual machine. Okay. We are going to create a virtual machine. Virtual machine
means it's not a, it's not a real machine. So whatever you are seeing on the screen is a real machine.
Okay. Which has, is my laptop guys. It has the windows 10 operating system installed. Right. So, but
virtual machine is not like my laptop. Okay. In the same, in the real machine,
Okay. In the real machine, we are going to create, we can create, in the real machine, we can create
multiple virtual machines. These are not real machines. Virtual means they are virtual. Okay. They are
not real. Okay. Like that. We can create virtual machines, multiple virtual machines. So, since in the real
machine, I already have the windows operating system installed. i will create a virtual machine, okay,
which is a temporary or not real machine and show you how to create a linux operating system in that
virtual machine.
So how to create that virtual machines? So here it will be like this, guys. This is your real machine. This is
a real machine, which is physical, okay? This is a physical machine. Physical, physical, okay?
Physical, real machine. That means it exists. it's an object, like it's a real object which you can touch and
feel okay it is a laptop, okay? It's nothing but my laptop. My laptop, okay? But in this i am going to create
some virtual machines. These are not, these are like digital, okay? These are just just software not the
real physical or something like my laptop, okay? These are like, like this in the same environment, same
real machine you can create multiple okay you can create multiple machines uh you can you can create
like a linux machine here, okay? Some other machine here. Some other uh os there are a lot of
operating systems in the world. So you can have different operating systems in the same machine.
So this is a virtual machine. And this is also a virtual machine. So let me show you an image, guys, okay?
On how a virtual machine will look like. Before I install or before i explain how to create this virtual
machine, with the linux operating system. Let me give a high level idea of what exactly the virtual
machine. Okay. Let's see if i can find some examples on virtual machines uh virtual linux os in os
machine in Windows. Images. Let's go for images. Let's see if i can find, get an image. You see here. So
this is a perfect image guys. Okay. So let me click if it can open in the full mode. We need a full screen so
that you can understand what exactly it is.
Yeah, here you see guys, this particular thing is a real machine which has Windows operating system.
Inside that, someone has launched a virtual machine. This part is a virtual machine. It has a Linux Ubuntu
operating system installed. Okay. You can see right inside this, it looks like a normal Windows window.
Okay, it is a window. A window, inside window, we have the Linux operating system. Linux operating
system is now there in the Windows now. From the Windows operating system, we created a Linux
operating system in a separate window. Like this, you can create multiple virtual machines in separate
windows. So here, this box is a Linux. Inside Windows, we have Linux. We don't have to buy or purchase
another machine for Linux operating system.
From the same Windows machine, we can create this kind of virtual machine which is not physical or
real. Okay? In that virtual machine, we can create the ubuntu operating system okay we can we can use
the ubuntu operating system. So, in this video session i am going to practically demonstrate how to
create this virtual machine and how to install the linux operating system inside this virtual machine.
Okay? So, hope you got some high level idea on what i am going to explain. Fine. Now, let's get started
with the practical demonstration, guys. Okay? On how to create the linux virtual machine. So, in order to
create the linux virtual machine, we need few softwares. Okay? There are few things that we need the
first thing is the first thing is we need to install virtual box virtual box software in our windows operating
system, we have to install this virtual box software this is the first step we have to do.
We can say step one step hash one what step hash one we have to install virtual box software So, way to
get this virtual box software virtual software is free, guys. Okay? It's free. You don't have to pay
anything. Simply Google search for virtual box download simple okay virtual box download and uh you
will get this link like a downloads it belongs to oracle company, guys. Okay? So, it's a free one. Open
source and free one. Anyone can use and download for free. So, download oracle vm virtual box Okay,
click on this. So maybe this is a wiki page. It seems you can also do from here guys. Okay, let's see. Let's
see whether let's open this link and see if this is the same.
Yeah, this is also fine. The first link is fine. [Link] wiki downloads. Okay, this is fine. You can go
there and in this downloads section of this virtual box. Okay, you see some platforms here. So in which
operating system you want to install this virtual box software. Okay. In which operating system you want
to install this virtual box software? Do you want to install this virtual box on windows operating system
or some osx or linux or solaris or which operating system my my real or physical uh machine has this
windows operating system. So I have to select windows host. Okay. Click on this. You see the software
will get downloaded guys. It will take a bit of time. Okay. so here you see virtualbox 6.8 point 1.8 is
taking some time, 36 minutes and all.
Sometimes two hours it is saying, based on the network speed. So I would like to cancel this because i
already downloaded this for you guys okay so uh but in your case, you have to completely download. In
my case, I already downloaded this and kept it here. Okay, it's already there in my machine. So this
software, once downloaded, you will get this kind of exe file, application exe file. So double click on this.
Okay, the installation will start when you double click on this virtual box. And you got this virtual box
installation wizard. Click on next. I can click on next. That's fine. Click on next. Yes. Install. Okay, just go
with the flow guys. You don't have to select any other option.
Just click on next and until you get this install done. You just have to go like that. So it will take a while
guys for it to get installed. I may pause and resume the videos just to save your time guys. Okay. so i may
pass and resume the videos whenever it is required. In this video session, because these installations
and all those things will take a lot of time. And you need to click on the s button if any user access
control prompt prompts up. okay so then the installation will start here. And once the installation is
completed, you can click on this finish button by keeping this checkbox option selected so that once the
installation is done. This particular virtual box software, whatever we have installed will automatically
launch by itself.
Click on finish. So it's asking me to restart my system guys to take effect. I'll try to do it later. Okay. So
no, I will select no. Now I even have the virtual box opened also. So Oracle VM virtual box manager is up.
This is a software guys. Okay. This is a software. Whatever we just now installed, right? This software we
got. As part of the installation of the VirtualBox, we got this particular software. So you can close this
and relaunch this if you want. In the Windows search, you just need to type VirtualBox. After installing
the software, VirtualBox software, if you search for VirtualBox here, you'll get this option, Oracle VM
VirtualBox. Select this. It will launch again. So it will launch again.
So this is the software which got launched. in the software, we can create the virtual machines, okay?
Using the software, we can create the virtual machines. Which virtual machine we want to create? We
want to create a linux virtual machine, okay? We want to create a linux virtual machine. For that, click
on new, okay? New. And create new virtual machine, okay, will come. Create virtual machine with dialog
will come. In this, you need to search for Ubuntu, okay? ubuntu is one of the flavor of the linux
operating system. So in this video session i am going to install ubuntu flavor of linux operating system.
When you search for Ubuntu, few other things here will be selected. For example, here if i search for
windows right microsoft the windows is getting selected.
But when i search Ubuntu, you see type is Linux. Okay, Ubuntu is one of the flavor of the linux and uh
ubuntu 64-bit version. Okay, that's fine guys. Okay, click on next. So, I just selected next here, guys, on
the create virtual machine. Taking some time. Yeah, that's fine the next uh next screen came where you
need to select the memory. Better to select more memory, guys, otherwise it will be very slow. So, I'll be
preferring to select 2048 that is that okay for 2gb RAM. I'm just giving 2gb RAM, nothing but. Click on
next uh and then hard disk, create a virtual hard disk now will be fine. Okay. then say create here artist
file type. So virtual hard disk. Select this virtual hard disk type.
and click on next. And dynamically allocated is fine. Click on next. Then here how much size. png is far
enough. So click on create. Okay. The hard disk has been created. The RAM has been decided. So all
those things are now good. Now, next thing is we need to click on the start button. Okay. We need to
click on this start button. Select this. You see here, under this Oracle VM Virtual Box Manager, we got
this Ubuntu created. A temporary thing. Ubuntu is now powered off. By selecting this, just now we
created, right? This is a virtual machine. Ubuntu virtual machine. Select this and click on the start button.
Anyhow, it will be by default selected. You don't have to select if you have to.
If not selected, you can select it. so select it and click on the start button you will get this kind of dialog
where open to uh select startup disk it is saying so here is the thing guys okay at this place you need to
provide the disk okay operating system disk you have to provide for example if you have to install
windows operating system in your machine microsoft windows 10 or any other version of the windows
operating system will have a cd or something kind of thing right pen drive or kind of disk kind of thing
That you need to put into your machine. Then only, from that particular disk only, the installation of that
Windows operating system will start in your machine.
Similarly, in this virtual box also, while creating this virtual machine, it will ask for the disk. A kind of disk.
So, how to get this disk? How to get this disk? So, the simple guys, even Linux Ubuntu operating system
is free, guys. Unlike Windows operating system, Ubuntu Linux operating system is free. It's an open
source and free one. you can download it. So, how to download it? You have to download from this
page like a download ubuntu something like this okay that is fine. Download Ubuntu. So, they have a
website. Ubuntu Linux operating system people have this website like [Link] under download
under desktop this uh link should be clicked. So, you will be taken to this particular page open to
download desktop page, okay?
Or any other page where the download is available. So, here, download Ubuntu. You have the button of
download guys. You have a button to download. Ubuntu 20.0.4 is now available as for 17.5.2020. So
when you click on download, thank you for downloading Ubuntu desktop. Your download should start
automatically. You see some ISO file is getting downloaded, right? As you can see here, Ubuntu iPhone
20.4 some ISO file. This is a disk kind of file guys. ISO is a virtual disk kind of file. So it will take a lot of
time to download guys. It's showing as 21 minutes but in reality it may take one hour also for a lot of
people. So simply I will cancel it because I already downloaded it in my machine.
Just go to my downloads. I'm just going to my downloads folder where you see this is the ISO file. Disk
image file. It's not a real physical disk but a virtual disk kind of thing. It's a kind of file created from the
disk which you can use in the place of the disk. Ubuntu 20.04 desktop something. now this this file i have
to have to provide here. Okay. Select the startup disk. How to select? Click on this folder icon and open
this selector. Click on add. Click on add and go to your downloads and select this ubuntu 20.04 desktop.
This ISO file, just select it and say open. Okay. This got selected here. There is other way also guys for
selecting this. Okay.
So now say choose. Choose. So this got selected here in some other case in some other case uh you
have this settings option. In settings option, you can do so, okay? So now click on start button. I'll show
you the how to select this disk in the settings, okay? So that is also is possible, but this is enough, okay?
If it is launching, if it is asking you to select a disk, you have to select it. you can close these things. It's
not required. So, fine. The installation has started, guys. It will take a while. Okay? Installation has
started so i was talking about showing another way of providing the disk image right select this select
this ubuntu while it was stopped and click on settings.
Then in settings, storage, you have to go to storage. Here, you need to select this option and you have to
select this option. And you have to choose the disk from here. Okay? You have to choose. Already the
disk is selected. If not, you will get the similar options. On how to select the iso file of the disk, you will
get similar options. You can select that disk file. ISO disk file. And here, this option should be changed to
Ubuntu. Okay? Then also it's fine. If it is asking you directly when you launch this virtual machine, like
start the virtual machine if it is asking you, then that's fine. You can select from there. Otherwise, you
can go to this, select this and go to settings.
Then, what is that place? Settings and storage and then select here. Okay. And say okay and start. Any
two ways. There are two ways guys. Okay. Whatever is best for you, you can choose the iso file disk of
the ubuntu linux operating system file. Fine. So this will take a while guys. So let's wait for it to progress.
Now it started loading something. As you can see, Ubuntu logo has come and the operating system has
started loading. it will also take a while. So finally, we got this linux ubuntu screen. And there are a lot of
things to be done, guys, okay? The operating system has not been installed it okay? So it's just loading
the installation program. We are going to get some installation wizard for the Linux, okay?
So like this kind of installation wizard will come with the install and you will be asked you will you have
to select this install ubuntu option guys okay we're going to install ubuntu button just click on this. it
may be a bit slow, but uh be patient guys. Just click on this install Ubuntu. So, it's loading. And after a
while, you will get this keyboard layout where in the first screen also you have to select english guys. If
any other language is selected for ubuntu uh before clicking on that install button, if english is not
selected, you have to select english and then do that otherwise uh okay that's fine uh in the next screen,
you got uh this keyboard layout where again,
english us and english users need to be selected and click on continue here. okay click on continue.
Yeah, the next screen came where updates and other software. okay so don't change anything. Click on
continue. So it is taking some time. now you got another screen like installation type and you have to go
with the default option guys there is this kind install ubuntu is fine okay click on install now. Now you
got a, now you got a confirmation dialog like write the changes to this Okay, click on continue. Now you
got, uh, where are you okay i am from India. So I'm just selecting india if you are from a different
country, you can select that country and say click on continue. Now you got uh who are you?
Yeah, you need to provide some details, guys. Okay, so let me provide some details like this uh i'm just
giving my name here uh one minute a bit slow yeah i'm just giving my name here and some computer
name. Anything you can give any name here guys. So I don't virtual box is also fine. Then pick up a
username and giving the username as my first name plus last name together. Then I need to choose a
password. I'm just giving some password. Okay, better to choose a better password here. Okay, done.
Next thing is uh i'm just selecting to log in automatically because i will be the only person using this
machine. So, let me click on continue. So, the installation, the real installation of ubuntu linux operating
system has started just now, okay?
It's copying files. It will take a lot of time, guys. You need to be patient and wait for the entire installation
to complete. Okay, it will take a lot of time. The topping of files is done here as you can see and the
installation of the system has started now. as i said the installation is going to take a lot of time guys you
see still a lot of time it will take to actually complete the process okay we have to wait until this
installation completes as you can see we got a dialog saying that the installation has completed and we
need to restart now okay we need to select this restart now button to get the installation ready fine it
has to restart now and then we should see our linux operating system should be ready
Yeah, it's starting now. Okay. That's okay. Whatever you are seeing on the screen is okay guys uh it will
start, not a problem. So it will be bit slow guys uh So we have to be very patient. During the entire
process, we should be very patient. It will be slow. So now it is saying, please remove the installation
medium and then press enter. So what does it mean? So it means that whatever the ISO file we have
provided, right, disk image for Ubuntu operating system, we have to remove that. Okay. Earlier we have
that. Now we have to remove that. From where we have to remove that? Let's go to this and select this.
Again, select settings. then go to storage it's not there okay so it's not there already it's removed but
somehow it is showing.
Fine. Yeah. fine You see if any other place we can do so. Okay, settings. Go to settings and storage. It's
not there. Okay, it looks like it's got removed automatically. i'm just changing to some other thing just to
make sure like you don't have anything. Fine. Select this once that is done and press enter. Let's see
what will happen this time. So. You see. Uh, it is taking some time guys so we have to be like we have to
wait for it to again go there. As you can see now, the ubuntu is now loading. Okay, it's still loading, guys.
Now I'm getting some blank screen. Don't worry. We have to wait for a while so that it will display the
actual OS.
Finally, we got our operating system ready guys. Linux operating system installed in a virtual machine is
now ready. Okay. So we can do one more thing. We can simply power it off. Okay. Since it is ready, we
just want to see the last check. We will try to power off. We will turn it off. And this time I am going to
select the restart option. I am just going to restart my operating system to see everything is in place.
This is the final check guys. This is the final check. To see that everything is okay. My operating system.
That is Linux Ubuntu operating system should restart now without any problems. Then I can confirm
that my Linux Ubuntu operating system is now ready.
So let's wait for the Ubuntu Linux operating system to restart. So it's restarting guys. It will take a while
to start up again. so guys, now we got our uh linux ubuntu operating system to get restarted. It got
restarted and successfully launched like this. Okay, so things are good. Things are good uh as you can
see now, we have our like a virtual machine ready. We have our virtual machine ready guys. So this is a
linux ubuntu virtual machine which is which we can use from our windows okay so from our windows
this is our windows laptop my windows laptop is here and in that if i launch this virtual box i can launch
this virtual box similar to ubuntu i can create multiple virtual boxes here okay here only one one box is
there right ubuntu linux virtual machine is there apart from that we can create many more okay anyhow
anyhow so we we
we have we actually need only one virtual box at this moment. That is a linux ubuntu virtual box. So why
we need this virtual box that is linux ubuntu virtual box why why actually we need this particular virtual
box? The only reason here is uh we need to install MySQL, okay? We need to install mysql in this linux
ubuntu operating system. So how to install the MySQL? db software in this linux ubuntu operating
system. That thing i'm going to explain in the next video session, guys. Okay? In the next video session,
I'm going to practically demonstrate how to install mysql db software in this oracle vm virtual box having
the linux ubuntu operating system. So that's it, guys. Hope you understood how to create a linux virtual
operating system machine.
And so that's it. we'll meet in the next video session. Thank you, guys. See you. Bye.
So, in the previous video, in the previous video, I explained how to create, how to create a Linux
Ubuntu, Linux Ubuntu virtual machine. Okay? As I don't have the Linux machine with me, what I did is, in
my Windows machine, I created a Linux Ubuntu virtual machine. So how to create this linux ubuntu
virtual machine? I explained in the previous video, guys.
If you don't have the linux ubuntu virtual machine with you, you can go to the previous video, guys, and
get that virtual machine created for this linux linux ubuntu operating system and then come back to this
video. In this video i am going to directly explain how to install this mysql in the created linux machine.
So let's move to the practical mode. where i am going to practically explain how to install mysql in the
linux machine. So, here, this is the linux virtual machine, guys, okay? It's not the real machine. It's a
virtual machine. So, in my windows machine, in my windows machine, I created this linux ubuntu virtual
machine okay in the using this virtual box software now uh i am seeing some unnecessary screens here.
so i'm just going to skip guys, okay? These are not required. Just keep on clicking next and click on keep
on clicking done so that you will see the actual linux linux ubuntu operating system. This is the linux
ubuntu operating system, guys, okay? This is the linux ubuntu operating system. You are able to, okay?
We are able to use this linux ubuntu operating system from the windows machine itself, okay? This is
not a real machine. This is a virtual machine okay sorry uh let me, okay? This is a virtual machine, guys.
so what i'm going to do here is i'm going to explain how to install mysql in this linux ubuntu operating
system. How to do that? In Linux, if you have to install MySQL, click on this.
And you need to get, you need to find the terminal, guys,
okay? Terminal. So terminal is something like a command line kind of thing in Windows, okay? In Linux,
we call it as terminal. So it has to launch like this. The terminal has been launched. you can clear the
things. Just type the clear command. It will clear the unnecessary things. So here, in this command, you
have to first write this statement like sudo apt-get okay sudo apt-get update so before installing
anything in your linux ubuntu operating system, you have to run this command guys okay sudo apt-get
update. Okay? After the things are up to date, after the existing resources are updated up to date, then
you can install the new software. That's a better way.
So run it. It will ask for the password of this Linux. Okay? This Linux Ubuntu operating system has a
password. Right? When I created this linux Ubuntu, I gave the password to log into this operating
system. Okay? So that password you have to give here. I'm just giving my password that i have set for
this machine. And once you give the correct password, Okay. It will start getting all these things. Okay. It
will start getting all these things. It will update the existing resources like this. It will take a while, guys.
So, once the updation is completed of the existing resources, you will see this done. Okay. You will see
this done. Fine. Now, let's install MySQL. What is the command for installing the mysql in linux Ubuntu?
The command is nothing but sudo apt-get Install. The package name is MySQL server. Okay. You have to
remember this guys. Pseudo space apt-get install MySQL-server. When you enter this, you see the
MySQL started installing and it's asking you, do you want to continue? Yes, I would like to continue. Type
y and press enter. Then it will install the MySQL server in your linux ubuntu operating system. So it will
take, it's going on. Let's wait for it to complete guys so it's fetching something it has okay so it's reading
the database lot of things are going on. Let's wait for it to complete. as you can see, the mysql has
successfully installed now. Now, the next step is to make it secure. Whatever the mysql installation you
have done in this linux ubuntu operating system, you have to make that mysql a bit secured one by
providing the proper passwords and all the stuff, okay?
For doing that, we have another command. That is sudo mysql Underscore. Secure. Underscore.
Installation. Okay. Pseudo space. MySQL underscore secure underscore installation and press enter
guys. So it's asking. It's asking for something. What is that? Press Y for s and any other key for no. And
before that what is what actually it is asking, we have to find out. So securing the mysql server
deployment, connecting to mysql using a blank password validated password component can be used to
test passwords and improve security. So, would you like to set up validated password component yes if
uh if we set up this validated password component, guys, then we can set a password to this mysql
server. Otherwise, the mysql server will not have any password.
It's better to secure the mysql server by providing a password, which is only possible when you set up
this welded password component so i will say Y. Okay? Simply say y and press Enter, guys. Now it's
asking you whether you want to set the password with the low security, medium security or strong
security. As this environment is a demo environment, I'm not going to continue this environment in
future guys. After explaining in this video, I may move it to trash. So this is just for your explanation. But
in real time, you may have to use a strong password. But in this video, I'm trying to use a low password.
That is, I'm going to set the security of the password level 2. I don't want to create a complex password.
Rather, I would like to go with a simple password. So for that, the low level security has the length
should be 8 or greater than 8. That is fine. Minimum, only one rule is there. That is, the size of the
password should be 8. Apart from that, no rule is there. If you go for medium level, you will get more
advanced features in password setting. That is, the password should have numerical value, mixed case
and all that stuff. And strong will have more rules. I would like to go with the low. Low kind of password.
Okay, low complex kind of password or simple password, which is just by providing the size of 8, it will
be done. So here i am going to enter 0 guys.
Okay, so that i can set the low password. So please set the password for the root. The root is a username
guys. Root, when you install MySQL, the super user that will be created in the mysql for accessing it is
root. Okay, username is root. And password i would like to set as root One, two, three, four. Okay. I'm
just giving the password as root one, two, three, four. I have to re-enter the password, guys. Okay. I
have to confirm it. Again, entering root one, two, three, four. Enter. So, do you wish to continue with the
password provided? Yes. I would like to set the password as root one, two, three, four. You have to
remember this password, guys. Later, we have to use this password in the upcoming videos and also in
the same video also if required.
Okay. Say Y and press enter. remove anonymous users. I don't want to remove anything, guys, so i will
say N. And disallow root login remotely. I don't want to restrict remote login, so i will say N. I'm saying
no for everything, okay? Remove test data base and access access to it. I don't want to remove the test
database, okay? I'm just saying N. And reload privileges table now. I don't want to reload privileges table
now, so i'm saying N. So, done, guys, okay? So, security is also done. Now, what is the next step? Next
step is to see the status of MySQL. Okay? For that, we have command like, what is the status? Whether
the mysql is running or what whatever it's uh like turned off or it's on.
We have to find out the status, right? So, for that, we have a command like sudo service mysql status.
That's it. Okay? sudo space service space mysql space status enter it if you get if you get this kind of
result, okay? If you get this kind of result that means that means what guys the mysql is running,
currently running so here uh i'll say ctrl z guys so that uh okay this uh this will end. So you are not able to
go to the next command, right? So the command was not getting displayed. So when i press ctrl Z, it will
take you to the command. Now, I would like to stop the MySQL, okay? i would like to stop the MySQL.
For that also there is a command.
Earlier command was sudo service MySQL. I was giving status to find the current state of the status of
the running of the mysql community server, right? So I got the result that it is running. You see here,
active running was coming, right? With the previous command. Now I would like to stop it. I would like
to stop this mysql server so further the command is sudo service mysql stop. When I say enter, Okay,
when i say enter, so it has stopped mostly. So I will give the previous command that is sudo service
mysql status again. You see, it's inactive. You see inactive dead. It's coming as inactive dead. So again,
control z so that you can see the command prompt. Now let's start it again.
How to start the mysql server? sudo service sudo service mysql start you have to say enter. Okay, you
have to say start and enter. So now let's find the status. Sudo service, MySQL, status. Let's find the
status, whether the mysql has started or not. Because in the previous command i i asked it to start. So
here, active and running. That means it has started. Okay, it's running now. So we have stopped the
mysql service. We have restarted the mysql service. And we now know how to find the status, whether
the mysql server is running or it's like inactive or whatever it is, okay? Now, anyhow, using the last
statement, I started it, right? I started the mysql server. Currently, the mysql server is running in the in
this linux ubuntu operating system what's the next guys the next is to the next is to uh like uh we need
to connect to MySQL, okay?
So, this is just starting, guys, okay? The MySQL server is running. But how to connect to this MySQL?
What is the way of connecting to MySQL server? MySQL server is running in my Ubuntu Linux operating
system. But how to connect to that? There should be a user, right? There should be a user using the
credentials of that particular user. We can connect to the MySQL server. If you remember, while
installing this MySQL and securing it, and we have set a password. For which username we have set the
password? We have set the password to the... which username guys root username if you remember
and what is the password i gave the password like complexity as zero if you remember right the like not
complex simple password but the size of the password should be eight eight uh eight so the password
was like i said the password has one two three four root one two three four is the password and root is
the username okay root is the username and root one two three four is the password so using these
details we can now connect to the mysql server
but there is a command, okay? We need to type the command for connecting to the mysql server. What
is the command? You have to say sudo sudo mysql hyphen u. After hyphen u, here u stands for
username. What is the username of the user? Root. Root is the username. Then we have to type hyphen
p. But you should not mention any password here in this statement. This is the end of the statement,
guys. sudo mysql hyphen u root is a username, hyphen P, don't provide any password and press enter. It
will ask for the password, guys. Now give the, whatever the password you created for the root user, that
is root one two three four enter so you see before before this before i entered this command, the
command prompt was giving arun motori at the rate arun motori hyphen virtual box and dollar symbol,
right?
Then you are able to provide these comments now the command, command line got changed to my sql
That means we got connected to the MySQL. Okay. We installed MySQL. We created the password for
the MySQL. We restarted the MySQL. Now we got connected to the MySQL. Okay. Now here we need
to, we can perform all the SQL operations here. All the SQL statements that I was explaining as part of
the previous videos, all those things you can perform here. Let's say in this MySQL server, let's see
whether there are any existing databases. What is the command guys? What is the SQLs? command for
finding the existing databases in the mysql server. Simple, guys. Show databases, you have to say. Enter.
So, these are the existing databases okay uh then then we can do a lot of stuff, guys, okay?
So, these are the existing databases uh we can create the databases we can uh okay we can do a lot of
stuff. Create database. qfox okay? I'm just creating a new database in this mysql server. with the name
QFox. In this existing database list, information schema, MySQL performance underscore schemas are
there. But I would like to get another database that is create database QFox and press enter. You see,
query okay, one row affected. Now run the same command, show databases. Now the list should have
another extra database that I just now created here. Okay, you see, now earlier databases are only four,
but they are final and including a database name that I gave here. So we created a new database here.
and in this qfx database, out of all this five database, I would like to work on the qfx database.
What is the command in SQL? Use qfx okay? Use the database name. Enter. Now the database got
changed. That is, we now are working with the qfx database out of all the all the available database in
the mysql server. Now in this qfx database, let's find out any existing tables are there. So for that, we
have show tables. Empty set means no tables are available. Let's create a new table. Create table. EMP1.
ID. Okay. ID. Int data type. Name. Where care. Some 15 I am giving. And press enter. The table got
created. So, now if I say show tables. I will get one table in the. Tables in QFX database are only one.
That is the newly created table. That is EMP1 table.
Now. I would like to see if there is any data available in this EMP1 table. What is the command? Select
star from EMP1. If I say select star from EMP1, if any records are there in this EMP1 table, they will be
coming. But this is a newly created table. You will get empty set because there are no records. It just
now has been created and there is no possibility of having records in this EMP1 table. Now let's insert
some records. how to insert some records using the sql statements? I have to type these comments like
insert into emp1 values, let's say one Arun, like this another another record i am trying to insert emp1
values another record i am trying to insert, insert into emp1 values, three comma Okay, like this, three
records i am inserting.
now three records got inserted how to check that again i have to run the same command select star
from emp1 okay select star from emp1 and press enter you see now the table got create after the table
got created after i inserted the records now i can see these three reports available in this emp1 table
like this guys we can perform any operations okay we can perform any operations on this uh mysql
server okay after connecting to mysql server can perform any sql operations using any sql statement we
can perform now what i would like to do is i would like to delete this table okay i don't want to have this
table so how to delete the table drop drop i mean not drop i will say delete delete table emp1 okay
delete table emp1 enter so there is some error delete
what is the table? EMP1 where id is equal to one Enter. So, I am doing some mistake here uh coming to
the table. Any spelling mistakes or delete uh okay okay delete star from table. Okay, like this. Let me
give. So, there is some pro okay sorry i did that i did another mistake, guys. Let me correct it. Delete star
from EMP1, okay? So, looks like i forgot the syntax of this delete uh statement uh maybe it is like delete
from EMP1, guys, okay? So, I was giving the wrong uh it's not delete table table name it's the delete
from table name. And press enter. This time it will be deleted, okay? I gave the wrong syntax for
deleting. so drop table. Drop table.
EMP1. Yeah. So here drop means completely the table will be deleted. Here delete means the records
inside that particular table will be deleted. Okay. These are the correct statements i delete from table
name. Drop table table name. Okay. These are the correct commands. Now we don't have any table.
Okay. Drop database. Database name is QFox. Enter. even the database got created deleted now. Now if
i say show databases, we'll get the default databases. Like this guys, you can perform all the sql
operations, okay, using the sql statements after connecting to this mysql server after connecting to this
mysql server you can perform all the sql operations using the different sql statements. These SQL
statements will allow you to create the databases, create the tables, okay, insert the data into the
tables, delete the data in the tables,
drop the tables, drop the databases and so on. Lot of comments will be there. So guys, this is how we
have to install mysql in a linux ubuntu machine. Hope you understood how to do it. In the next video
session i will be explaining one more important concept of how to connect how to connect to a remote
okay how to connect to a remote mysql installed machine using the putty software, okay? the next video
session i am going to explain how to connect to this mysql remote machine using a putty software let's
say this is a virtual machine and this is another machine right this is windows machine and this is
another virtual machine so assume that this linux ubuntu is a virtual machine and it's a remote machine
so if i have to connect from windows to this particular okay particular linux machine and then perform
this mysql operations on this linux machine okay from this windows machine
i would like to connect to this linux machine i need a software known as putty software okay from
windows machine using the putty software i'll be connected connecting to this linux ubuntu machine
and thereafter i will try to perform all these sql operations whatever i whatever i have practically
demonstrated just now okay from a different machine i want to do that so how to do that and all those
things i am going to explain about putty software in the next video session okay so that's it guys see you
in the next video session thank you bye
Part 99:Using Putty For Connecting to a Remote Machine having MySQL and Performing SQL
Operations Functions
Hello, everyone. Welcome to part 99 of sql for beginner series. In this video session, I am going to
explain on how to use putty software. This PuTTY software for connecting to a remote machine, having
mysql server installed, and then performing the sql operations.
So guys, in this video session, I am going to explain on how to use putty software
What is the purpose of using the PuTTY software? For connecting to a remote machine, we have to use
PuTTY software. If this remote machine has MySQL installed, if this remote machine has this MySQL
server installed, then if you use PuTTY software for connecting to this particular remote machine having
this MySQL server already installed, then what we can do, guys? we can we can perform we can perform
sql operations remotely okay we can perform sql operations remotely using the putty software. So you
have to understand few points here. With help of putty softwares, we can connect to the remote
machines. This is the first point. If this remote machine
okay if this remote machine already has this mysql server installed then using this putty software we can
connect to this remote machine having the mysql server installed and thereby we can perform sql
operations okay from remotely that means not from the remote machine but remotely we'll connect to
this remote machine and we can perform the sql operations so let me diagrammatically explain let's say
this is your laptop let's say this is your laptop guys. Okay. This is your laptop on desktop and uh let's say
here in your laptop. Let's say this is your Windows. Windows 10. I'm giving some exact details. Let's say
you have windows 10 os laptop and and there is another machine. And there is another machine.
So let's take another machine. Let's say this machine has. different OS. Let's say this machine has Linux
Ubuntu OS. Okay. Now in this Linux Ubuntu OS machine, we have MySQL installed. Okay. We have this
MySQL server installed already in this Linux Ubuntu OS machine. Now, now from windows 10 OS, I
would like to connect to this linux machine. I would like to connect from windows os to this linux os
machine. Using which software i need to connect using putty software okay using putty software using
putty software i can connect to this linux ubuntu os like this. And what i can perform more, after
connecting, After this machine got connected to this Linux machine, from this machine, we can execute
SQL queries. From this machine, we can execute SQL queries on the MySQL server of a remote machine.
So, we are able to run this SQL queries remotely. So, like this. If you want to achieve this kind of things, if
your own laptop does not have the MySQL installed, but in real time, what will be doing guys? Okay,
there will be lot of users and there will be a server machine. Like this, there will be a server. Okay? Like
this, there will be a server where mysql server will be installed. And everyone has to connect to this
server and then perform operations. Right? Everyone has to remotely connect to this server machine
and perform the operations. So like this, let's say this is one of the client machine. Like general
employees are using in in a company, let's say there are 10 employees.
Okay? let's there are 10 employees and there is only one server which has mysql server installed. And
from all the laptops of that 10 users in that particular company, everyone want to connect to the same
mysql server and perform sql operations. So how they are going to do it? So here, everyone, all those 10
people are going to install putty software in their machines. And using the putty software, by providing
the details of the server, they are going to connect to the server. And from their machines, They are
going to use the SQL queries on the MySQL server that is installed on the remote machine. So this is how
it happens guys. And now I am going to practically demonstrate. Now I am going to practically
demonstrate how to use the Putty software for connecting to a remote machine and thereby performing
the operations remotely on the MySQL server.
Putty software is just for connecting guys. It will connect. When you connect properly, then you can then
you can run the queries on this mysql server, okay? Remotely you can run. After, Putty software purpose
is to connect the two machines like this, okay? This machine to the this machine and thereafter
connection is established by the putty software. Then you can run sql queries. If MySQL server is
installed on the remote machine, then you can run the sql queries in your client machine, okay? Now, in
order for me to practically demonstrate how to use putty software, I need these two machines, right?
this windows 10 os machine i need and this linux Ubuntu
having the mysql server i need. No need to worry guys in the previous videos in the previous videos i
created two things.
Okay. As part of, as explained in the previous videos, I created two things in my machine. First thing is, I
created linux ubuntu virtual machine. Okay. i created in one of the previous videos. That is a last but one
video. I created linux ubuntu virtual machine so like this guys like this i created this is the linux ubuntu
virtual machine guys let me give password so that you can understand how it looks. So this is a remote
machine. Assuming that this is a remote machine. Okay. Okay. Let it log in so yeah this is a. linux ubuntu
operating system, okay, which i have installed in the, as a virtual machine. This is a virtual machine, guys.
Assume that this virtual machine that i have created as part of last but one video in the previous videos
is a remote machine.
Assume that this is a remote machine. This Linux machine is a remote machine in our practical
demonstration. Fine, this already created. Second thing is, I have already installed mysql server in the
linux machine. Okay. In this linux machine, you already installed mysql server. So where I, where i
explained this part in the previous video, guys. Okay. In the previous video, I explained how to install
mysql server in the linux machine. So these two prerequisites are done. So in your case also, guys, if you
are ready with these two steps that i explained as part of the previous two videos. Okay. Go, go, go
through the previous two videos. And if linux environment is not created, just create it if mysql server is
not installed in the linux minute machine
just install it, then come here guys okay in the now you can follow this session. After having these two
things ready, then you can follow this session, and i am going to do same thing like this so this is assume
that this is a remote machine, guys, like this. Remote server machine, which is having linux ubuntu
operating system installed, which is having the linux ubuntu operating system installed, and also has a
mysql server installed, okay? So, already everything is there. Now, from a remote machine, from a
remote machine, i would like to connect to this linux ubuntu operating system using the putty software.
Remote, I mean, from my laptop that is having the windows 10 operating system, I am going to connect
to this linux ubuntu operating system having the mysql server installed using the putty software.
How to do that? How to do that? For that, I need to download the putty software guys now have now i
have the client machine having the windows 10 operating system and now have the remote machine
having the linux ubuntu operating system with mysql server installed. Okay? So two things are there.
From this windows machine, I would like to connect to this linux machine. How to do that? Even though
both are there in my same machine, I'm going to replicate that. Even though this linux is in a different
machine, still we can follow the same process okay since i have don't have two multiple laptops, I'm
trying to put this windows and this linux environments in the same machine itself. Okay? Assume that
this is a remote machine somewhere available on my network.
Okay? And connect it to the internet. And this is my windows machine, which is my client regular usage
machine, using which i can connect to this linux virtual machine. Okay? How to do that? We need putty
software. So, from where i can get the putty software? So, you need to go to the downloads. Okay? You
need to go to the Google. Okay? And download. You need to download it, guys. Okay? You need to go to
google and say, download putty. When you say download putty, You will get this [Link] and
download putty link kind of thing. Just click on that link guys. Just click on that link. So it will take you to
the page. So this [Link] is kind of loading and here you see download putty option is there and here
you can download putty from here.
Then double click on the putty so that this putty configuration will be open Fine. Here I need to provide
the host name of the remote machine. I need to give the ip address of the remote machine. How to find
the ip address? So I have to go to the Linux. Open this. Then search for the terminal. Terminal. Search
for the terminal. Click on this. The terminal will be opened in a while. Here, I need to enter one
command, guys. That is ifconfig. This command is used for getting the IP address of this Linux machine.
So, in my Windows machine, if I say cmd, command prompt will come, right? In the command prompt, if
i say ipconfig then i will get the ip address, okay?
Then I will get the ip address of my machine. Similarly, in this linux machine, if i have to get the ip
address, I have to type this command ifconfig. So there is a difference, guys. You have to compare this.
In Windows machine, what is the command for finding the ip address of the machine that you are using?
ipconfig. Whereas in Linux, okay, Linux machine, the command is ifconfig. What is the difference?
between these two commands here f is different here ifconfig here ipconfig p is there f is there that is
the only difference, guys. Remaining everything is same. So here, when you say ifconfig, so, so command
ifconfig not found but can be installed. So it's by default, it's not giving okay we by default we cannot
directly run this ifconfig.
For this, we have to install this particular package. sudo apt install net hyphen tools, you have to say.
Before doing so, sudo apt hyphen gate i'll run this command guys okay so i'm i'm going to run this
command, that's for sure, okay? This is the command i have to run first. Let me copy paste somewhere
here so that i will, so i'll not forget this. One minute, I'm not able to get it outside uh let me copy and see
if i can uh get anywhere. So not that one. So let me type it somewhere. Okay. Sudo apt install. So what is
that command? Sudo apt install. Sudo apt install. Then followed by net hyphen tools i have to say. Okay.
Sudo apt install.
This command i have to execute afterwards anyhow. Okay. so before that, I will run another command
that is sudo apt get install sorry uh sudo apt-get update, I will say first okay it is asking for the password
of my linux machine linux ubuntu machine i am just giving the password of my linux ubuntu machine
now. You have to remember the passwords guys okay otherwise you will not be able to do anything. So,
let me update my existing repositories. After that, I will try to install this on net tools, okay? So, once this
says done, then you are free to install this uh sudo apt install okay sudo apt install net hyphen tools you
have to say net hyphen tools without installing this net tools, you cannot run this ifconfig.
That's the reason we are installing the tools here okay run it so do not take that much, I guess. Let's see
how much time it is going to take. Yeah, progress 80 percent almost there, right? Progress is 80 percent
fine crossing so once the net tools is installed, we are going to run the ifconfig command, okay? Without
this net tools we cannot run ifconfig. That's the reason we have to install it. So it's taking some time,
guys. Fine, let's wait for it to complete the installation of this net tools yeah it's done, guys, okay? Now
it's done. Now, you are free to run this command. Okay? ifconfig. So, in case of Windows, we have to
type ipconfig for finding the ip address. But in case of Linux, you have to type ifconfig command.
So, when you do so, this time it is working because we have installed the package. Whatever it whatever
the linux machine was suggesting the package to be installed, that package got installed and then
ifconfig was executed and we got the ip address. So, this is the ip address we got. Initial IP address is
[Link]. Type here. 10 point what is that command what is that ip address guys 10.0 dot then we have
2.15 this is ip address we got so using this ip address can we connect to this remote machine okay using
this ip address of this linux machine from my windows can i connect to this uh machine using putty putty
is there in my windows machine in the windows operating system i installed putty right from here i am
going to give the
ip address of the remote machine. That is linux ubuntu machine. [Link] is the ip address. Keep 22 as
it is. Copy this ip address. Paste into this saved session. And click open. Guys, before i am trying to
connect to this uh linux machine i am going to say that this putty is going to fail. Okay. I will show you
solution later point. For now i am giving you. Using the initial ip address given by this linux operating
system if i give give this ip address into the. putty and then provide the same ip address. If I entered into
the saved session and click on open here, SSH option is selected. That's fine. And here only on clean exit
is selected. That is also fine.
When you click on open, you are going to see an error. Okay. Even though you gave the proper details
here, this is the proper ip address of the linux machine. Okay. So we should be able to connect, right?
But we are going to get error, but how to resolve that errors i am going to explain later. First, let me
show you the error. after that, I will give you the solutions. Click on open. So, the command prompt got
opened. This should ask for your username, guys. Okay. So, but it's not asking here. Instead, after a
while, you will see a error message saying unable to connect our okay network error or whatever it is.
Okay. So, you are going to see an error in a while, guys.
Let's wait for the error to come. See, network error connection timed out. So, using putty, from my
windows machine, I am not able to connect to the remote machine like linux machine using PuTTY. So,
there is a problem. How to resolve that problem? So, in order to resolve this problem, we have to do
few things before doing this. Okay? Before using the PuTTY, we have to do few things. So, what is that
things? Just close this again open first thing is first thing is uh i need to open the terminal again guys.
Terminal. I have to open the terminal. one minute, let me type terminal properly. Yeah, this is a
terminal. Just open the terminal. And first, first step to overcome that network error problem of PuTTY.
Okay, we are not able to connect to a remote machine using putty guys. There is some problem coming.
So how to solve that? There are two ways. I mean, there is one way only, but there are two steps. That
is, first step is to install this ssh in your linux machine. Okay, first thing is you have to install SSH. So here,
come here. Now install ssh install how to install SSH? sudo apt install ssh i think this is a command we
have to give. Yes. sudo apt install ssh enter it. So it's asking for the password of this linux machine. So I'm
just giving the password. enter and uh that ssh will be installed. Do you want to continue? Yes. Type y
and press enter.
So it will be, the ssh will be installed. That's the first step. Okay, so progress is 38, 62. Fine. It has to be
completed guys. Let's wait for it to complete the installation of the ssh in this linux machine. So we are
not able to connect using putty to this linux machine because we don't, in linux machine, this ssh
software is not installed already, okay? Once we install, then we will be able to connect, okay? That's
one thing. So one step we are going to complete uh for solving the connection problem between the
two machines via PuTTY.
So, yeah, first step is completed, guys. That is, we have installed ssh now. Fine. Now, the next step is, the
next step is, close this, okay?
Power off. Turn it off, guys. Turn it off. Turn off the virtual machine. Say power off. So, virtual machine is
going to close completely. So, yeah, almost there. It is going to power off completely. Like real machine,
it is going to power off. It will take a while. Let it power off first. So, still I am seeing something. Yeah,
now it got completely powered off. Now, once a virtual machine is powered off, that Linux machine is
powered off, go to this virtual box. Okay. Where this virtual machine is there. Okay. It's now in powered
off state. You see Ubuntu is in powered off state. Linux Ubuntu is powered off. In the virtual box
manager, select this Ubuntu which is powered off and select settings.
Okay. Select the settings. Click on the settings guys. Then you will get this kind of settings. In settings,
select network. Network. Select Adapter one In Adapter one tab. Here. Attach it to. You have to select
host only adapter. Okay. Host only adapter you have to select. And go to advanced. Okay. After selecting
this host only adapter. You have to click on the advanced. And just click on this refresh icon. Okay. Just
click on this refresh icon. And see the mac address is getting changed. And then say
okay. Okay. This is the steps you have to follow guys. once that is done, now start the virtual machine
again. Start the virtual machine again, guys. Fine. So, let it start. It will take a while to start the virtual
machine.
The Linux machine is starting now again. Linux Ubuntu is starting now. Let it start completely. And we
should go to the terminal again. Okay. So, in the linux machine, we have to open the terminal again. And
then again, select the ip address. either using the command, which command is ifconfig command.
Okay. Using the ifconfig, we have to get the ip address the ip address earlier we got this ip address,
right? Before I did this operations, like installing the ssh and then changing the host only, uh, in the
adapter. Okay. By turning off the linux machine. So before doing that, we have this ip address, initial ip
address is [Link] but after starting the linux machine, again, after doing all this, uh, Click site sets
steps for resolving the problem and then starting the Linux machine.
The IP address is going to change this. We are going to get a new IP address. Let's see that once. Let's
wait for it to launch and then I will be showing you latest IP address. Fine, it's taking a while. Let's wait.
Okay so the remote machine has to launch completely and we should be able to see the home screen of
the linux machine. So we have to wait. There is no other way than waiting. Okay, still taking time. Okay,
still taking time. Yeah, it's going to start it it seems because i have seen the ubuntu logo disappear. That
means it's going to show us the screen of Linux, Ubuntu, after restarting or starting it. It's like starting a
machine, guys, okay? So even your laptop will take a lot of time to start, right?
Same thing happens with the uh like virtual box. So it is a virtual machine. it's not a physical or real
machine, but still it will take a lot of time, similar to the real machine. And as you can see, like while i
created this virtual box in one of the previous videos, I have given only 2gb so with 2gb how much speed
it can start and all the stuff you can expect right so it will it's going to take some time to launch. Fine, I
can see some arrow here, but i am not able to see any screen. Let's wait for the screen to appear. Yeah,
purple color came. That means we are almost there. Yeah. Now we are almost there guys. It got
launched completely.
Now click on this. Let's go to the terminal again. Click on this. Since we have used terminal multiple
times, it has given as a shortcut. So I clicked on it. And here you see, now after doing all the predict sites
like uh installing the ssh and then uh stop powering it off and then changing the adapter in network
settings adapted to host only adapter. then i am going to type ifconfig command, right? ifconfig. Now
this time you got another ip address, guys. Here you see you got another ip address, right? What is this
ip address 192 dot 168 dot 56 dot 103 103 like this we got. So this IP address we have to use. Now open
the putty. Where is putty, guys?
Putty is in my downloads. Just open this putty. And here, instead of giving the older IP address, I'm going
to give the latest IP address. That is [Link]. So I'm going to give that.
And SSH should be there. 22 should be there. And copy paste the same host IP address into the saved
session. And say, without changing anything, say open. You see some security alert is coming. That
means it's working fine. Click on yes guys. Okay. I'm okay with the security problem. Not a problem.
Okay. Just click on yes.
Now this time you see it's asking for the login as. So you have to login as. You have to give the username
of this Linux machine. What is the username? This Arun Motori is this part.
This is a username. Okay. I have to login as Arun Motori. Arun Motori. Enter. Now, it is asking for the
password. So, I have to give the password of this Linux Ubuntu operating system. Here, first, I have to
give the username of this Linux Ubuntu operating system. When Putty asks for the login as, I have to
give the username. That is this particular username. Then, I have to give the password of this particular
username of this Linux Ubuntu.
So, I am giving the password that I have set for the login in of this linux ubuntu operating system. Enter.
Then, welcome to Ubuntu. So, this putty software is there in my windows machine. And using putty
software, I connected to a remote machine that is linux Ubuntu.
That's why it is saying welcome to Ubuntu. Okay. Welcome to the remote machine that is Ubuntu. And
here, I got the command prompt of the Ubuntu. Okay. Whatever the command prompt that i am seeing
here, right, that you got here. Fine. Now, from this command i can connect to the mysql server mysql
server is installed in the linux machine i will try to connect to the mysql server how to connect the
command for connecting to mysql server is sudo sudo mysql hyphen u root hyphen p and press enter it
will ask for the password of this mysql server okay so the root user password is you have to remember
this password guys in the last session i explained Right? The last session, I explained what is the root
user and uh the password i have set.
If I remember, the password i have set is root one two three four okay root one two three four for this
root, super user of this mysql server installed in this linux machine. I give the password as root one two
three four after entering this, I have to press enter. So, So, sorry, try again. It is saying. Let me try again.
Root one two three four and press enter. So, it's not connecting. Maybe there is a problem guys uh the
problem here is i know what is the problem. So, here also i will try the same thing. Okay, sudo mysql
hyphen u root is u root password i have to say hyphen b and if i give the password as root one two three
four let's see what it will do. So it's saying, try again. I just got a doubt, guys, okay? I just got a, I'm just
saying control z so that i can go back. I just got a doubt like whether mysql server is running or not.
I just have to find out right before i uh connect like this to the server i i wanted to know like mysql
server is running in the linux operating system or not.
For that, we have a command, right? sudo service mysql i have to say status, enter. so let's see what will
be the result. sudo service mysql status. This is the command as far as i know. Okay, it's taking time.
Okay, it has to be by this time, but i'm not getting the result. So let's do one more thing. Let's say control
z here. i'm not it's not going i think uh let me close this terminal itself. Close the terminal and restart. As
it is not responding. So I'll say something like sudo service mysql. I'll say start. It's asking for the
password. Password for Arun Moturi. That means this username password Arun Moturi is like belong to
Linux Ubuntu and it's password like Linux Ubuntu password I have to give guys.
Enter. Let's see. Yeah. maybe it got started. Let's find the status now. sudo service mysql status Yeah, it's
now active and running. Okay, now say control z so that it will go to the next step. So now once this
status is active, then i think we can communicate. Okay, now let's give the password from the putty
software. Let's give the password. So that is a password is root one two three four Sorry, I gave the
wrong password, I guess. Yes, I gave the wrong password so so again i will run the command like sudo
mysql hyphen u root hyphen p enter it will ask for the password. Password is root one two three four
Enter. This should be the password, guys. Okay, it's not uh doing anything.
Here, let me check. sudo mysql hyphen u root hyphen p then root one two three four enter. It's
connected, right? The same thing i need to connect from here, but somehow it is not happening. sudo
mysql hyphen u root hyphen p I would give the password as root1234 enter. Okay. Somehow it's not
able to do. To the permitted by. Okay. So let me connect again. So open PuTTY. Put this IP address. Put
this IP address again. Say open. login as. Login as the username of the linux Ubuntu. What is the
username of linux Ubuntu? Arun Moturi. And password of linux ubuntu is. The password that i am going
to give. Now it got connected to the Ubuntu. Now my query should run. MySQL hyphen u root hyphen P.
So.
i gave the correct password guys uh but it's not working password for yeah it's asking for arun motori
password guys i thought like it's asking for the this password but here it is asking for arun motori
password as you can see here password for arun motori right that's what i'm doing mistake maybe i'll
give the ubuntu password here okay enter now it is asking for the actual password of the my sequel that
that's a logical that is a problem actually okay initially it is asking for our own motor is password that is a
Ubuntu password. After you give the open to password it's asking for the password of the my sequel
okay that root user my sequel what is the password of the root user my sequel root one two three four
enter yeah you see guys
this got connected now.
Small confusion, but that's fine. So, we have to read the things here okay it's here clearly it is asking for
password for our motor i was giving the password for the root user of MySQL, okay? That's where i did
the mistake. Now, here, you can run any query, guys, okay? So, you don't need this remote machine
now okay just uh collapse it and uh you don't need that remote machine from your you got connected
to the remote machine from your host machine and then you are able to connect to mysql server which
is there in the which is running in the remote machine. So, then, you can perform any operations like
show databases
if i say. Enter. All the databases that are there in the mysql server of the linux machine got displayed
here in the putty itself.
Now, you can create a database. Create database. Here, Fox, you can say enter. Now, say show
databases. The newly created database got displayed in the existing list of databases. Now, select this
database. Like, use QFox. Now, say, create a table under this QFox. Now, database got selected as QFox.
That means whatever the tables you create, they will be created under qfox database. So, let me create
a table. Create table, EMP1, ID, int, name, var char of 15. Okay, let's say i'm just creating this kind of
table. The table got created. If I say select star from, these are all sql statements, guys. Okay? i am
remotely connected to the linux ubuntu machine which has the mysql server installed and running.
Then, using Putty, I connected remotely.
And from the putty itself, I am running all the sql queries on the remote machine. Okay? So, this is how,
like, people work. So, in a company, a server machine will be there where linux kind of linux machine
will be there in in that mysql will be installed in the server linux server machine and all the people who
are actually working in the company, if they want to connect to that server machine, they can connect
using the Putty. And in PuTTY, after connecting to that MySQL server in that remote machine using
PuTTY, they can actually perform all the SQL operations. This is the reason why I was explaining all this
stuff. The last three videos, I was explaining about creating the Linux Ubuntu operating system in a
virtual box.
Then second thing, I explained how to install MySQL server in the Linux Ubuntu operating system. The
third video, I'm explaining how to use PuTTY for connecting to that remote Linux machine we created so
far. which has this mysql installed and running for performing the operations remotely from your host
machine like every employee can uh install this uh like i mean download this putty and then connect to
the remote machine and perform sql operations okay so remotely we can perform sql operations on the
remote linux ubuntu operating system if required okay which has this mysql server running now we
don't get any select star from mempments this table is empty right we have to insert some data for that,
we have these statements insert into emp1 values i will insert some two records.
Let's say i don't want to insert more uh insert into another record i'm inserting. Values into the table. So,
Varun. Second record. Now, if i say select star from EMP1, you see, the table got created. Like this, guys,
you can perform any operation, any sql operation on the databases of the mysql server which is running
on the remote machine. that is ubuntu linux remote machine in our example. Fine. How this is possible?
How all this is possible with the help of putty guys okay with the help of this Putty, we can do this kind of
stuff. So, hope, guys, you understood how to use putty for connecting to a remote machine, having the
mysql server installed in it, and then performing the sql operations remotely from your host machine.
You can perform the sql operations remotely on the remote machine, that is linux ubuntu in this case.
So, Varun. Second record. Now, if i say select star from EMP1, you see, the table got created. Like this,
guys, you can perform any operation, any sql operation on the databases of the mysql server which is
running on the remote machine. that is ubuntu linux remote machine in our example. Fine. How this is
possible? How all this is possible with the help of putty guys okay with the help of this Putty, we can do
this kind of stuff. So, hope, guys, you understood how to use putty for connecting to a remote machine,
having the mysql server installed in it, and then performing the sql operations remotely from your host
machine.
You can perform the sql operations remotely on the remote machine, that is linux ubuntu in this [Link]
this is it thank you bye
Day 113:Can ChatGPT Replace Human Software Testing_ Power of ChatGPT in your Testing Strategy
Hello all. Welcome to this session. In this session, I'm going to answer one curious question nowadays
everyone have in their mind. That is, can ChartGPT replace human software testing? Let me answer.
A simple and straightforward answer for this question is, can AI ChartGPT can replace software testing is
no, it cannot replace. Okay. Then what is the role of chart gpt then in software testing? Or what is the
power of using chart gpt in our testing strategy? If it's not going to replace, then how it is going to help
the software testers? Okay. In performing the tester in a efficient manner that i'm going to cover in this
session. Okay. As part of power of chart gpt in your testing strategy. So first of all, to, you know,
To justify my answer, that is no. Okay. That is ChatGPT is not going to replace the human software
tester. Hope you guys got relieved already. So, let me justify this answer why ChatGPT cannot replace
the software testing or human software testing. These are the several reasons. ChatGPT is only there to
assist and save our time, guys. Its intention is not to replace, guys. Okay. Its intention is to assist. That is
to help us. Time to... save our time and to make our testing more effective or efficient, whatever you
say. Okay. That's the only purpose of charge gpt guys, but it's not going to replace human software
testing. Okay. So here it's like an assistant guys. Okay. You see, let's say you are the person and you are
very busy person, let's say and because of your busyness right you are forgetting a lot of stuff or you are
not able to do the work properly.
Then you generally appoint an assistant, right? Who will. be behind you and you know, will be helping
you in organizing the things in a better way. Okay. Because you don't have so much of time to organize.
Okay. That assistant will do the stuff. Same thing here. chat GPT is like that guys. Okay. So chat GPT
understands that you guys are busy. Okay. While performing software testing and it is there before you
to help you as an assistant, an extra assistant for free if you are getting why don't you adapt? Right.
That's what is the role of chat GPT, guys. In simple terms, it acts like an assistant for us. The benefits of
having an assistant is like we will be able to do our work in a more efficient way.
We can focus on the required work and do it in a more efficient way. And with the help of the assistant,
we can do it in an efficient or effective manner. And at the same time, by having an assistant kind of chat
GPT in our testing, an additional hand will come because of which we can complete our testing in less
time. it will save our time, okay? So, whatever the time that you spend in software testing, right, that
will be reduced with the help of chargpt but it's not, its intention is not to replace the software testers.
So, why chargpt okay? Despite of helping you as an assistant and saving your time and making you guys
work in more efficient manner, why it's not able to replace the human software testers or set
testing process, human software testing process because it cannot understand the context case.
Humans have some intuition. They can think and they have some creativity, intuition kind of thing
because of which they take different kind of decisions and in different contexts and different situations,
they behave in a different manner or they act in a different manner. But ChatGPT is not prone to that. It
does the same thing in every context in every situation. Okay. So that skill chat gpt doesn't have, it
cannot fully understand the context and based on the context, how to act, how to behave. It doesn't
know that's where we as humans are better in testing. So we cannot say that chat gpt is entirely kind of
thing. Okay. Replacing, but it's acting like an assistant.
That's why, even though it doesn't have human intention and creativity, but still chat GPT, can help us.
One simple example I'll take apart from ChartGPT, like in the olden days when the calculator was not
invented, people used to calculate in different formats. It used to take a lot of time for the people to do
some simple mathematical calculations without the calculator. When the calculator was not invented,
people used to take a lot of time to get the result of the calculations. But nowadays, what's happening?
Calculator kind of thing, a product known as calculator is available in the market. Now it's available
everywhere in the form of software, physical device, everything it is there. So whatever it may be, you
just enter the numbers and perform the calculation.
You are getting the result. That does mean that there's no use of the human beings. Just because a
calculator is replacing your mathematical calculations, can you say that the calculator is replacing you?
The same thing applies here. There the calculator is acting like an assistant, an extra help person for you.
to save your time while doing the calculations. But still, woman has to, human beings have to apply their
mind, intuition, and creativity to do the real work, right? Calculator is just helping you in saving the time
while performing the calculations. What do you want with the results that you are getting? is up to you,
right? The same thing here also, guys. Just replace the calculator with this chat gpt here, okay? So, chat
GPT is only there to help you out, to save your time, okay?
Uh, to make your work uh to be done in an efficient manner. That's the only purpose of charge gpt here
okay but it cannot do everything that humans can do while performing software testing you see uh it
won't work outside the box, case okay? It has some limitations charge gpt has some limitations, guys,
where charge gpt is not going to work outside the box. There's some boundary drawn and it is being
trained chat gpt is kind of a tool which is trained based on some information, guys, okay? It will act
according to the information. If you ask something out of that information that is trained on, it will
cleverly give you an answer saying that, okay, this is not expected. I cannot give you or something.
It will diplomatically or cleverly answer you something so that you will feel that, okay, it's answered
something. It has some lines, boundaries where it cannot answer something because it's not trained on
something. It's not possible. It's keeping on evolving. That's okay. The chat GPT is nowadays evolving
and it is kind of eating the information and, you know, being trained on several types of information and
based on the information it got only, it can act. But something new come, dynamically it cannot answer
something, right? Okay. Whatever it doesn't know, it cannot answer. You have to educate it again.
There's a problem. So, and something that humans can do that chat gpt cannot do is judging process.
Okay. So, judging the results, guys. Okay. So, whatever the results that are generated by chat GPT,
Whatever the results, testing results are generated by ChartGPT, they may not be accurate. It cannot do
testing physically anyhow, but still speaking, ChartGPT cannot judge the results. Again, human
intervention is required to review that thing that is generated as a result by ChartGPT to see whether
the result generated by ChartGPT is correct or not. Again, we need human help only. We cannot blindly
depend on chat GPT guys. Okay. Sometimes it will, most of the times it will give you the correct answers,
but still there's a possibility that chat GPT may give you wrong answers sometimes. Okay. So you have to
make sure that kind of, okay. You have, you need, your human intervention or judgment is required in
this case. And the other important thing that chat GPT cannot do is cannot communicate like humans
guys.
Okay. So when you're performing software testing, it's not blindly that you are sitting before a machine
and you know, You are just performing the testing. You have to talk to your clients. You have to attend
the meetings. You have to talk to your developers if you need some information about something, about
requirements. To that extent, ChatGPT cannot go. So humans are very good with communication. They
can communicate and find out something. But ChatGPT cannot come outside of your laptop and go here
and there, roam here and there, and chat with the clients and all. That's not possible for ChatGPT.
Something is out of the box, right? Which is not possible for ChatGPT. And final thing is inability to
physically test. Can ChatGPT move my mouse like the way I'm moving here?
Can ChatGPT do that? No. Can it type keywords on my behalf while performing the testing? No.
Physically, it cannot perform any software testing, guys. So there's no point that ChatGPT is going to
replace software testing. It's going to help the software testers to... make the testing process efficient or
to save the time of the testers. Okay. While doing some activities regarding the software testing that i'm
going to cover now, I'm going to practically show you how to use chat GPT. Okay. To utilize that as an
assistant, which is going to help you to save your time and to do your testing work in an efficient manner
that i'm going to show you i'll prove you practically here okay so these are few things that i'm going to
show you guys there are many other stuff.
i took only this code for now but uh there may be others also i cannot say whatever i wrote down here
will be not be the list of the things right there may be other things that chat gpt may help you but these
are the major ones i figured out uh to explain you guys okay so in a practical manner first learning if you
are the one who are who is who want to learn some software testing related stuff you can use chat gpt
guys okay i'll show you few examples first i'll open this browser and you know uh i'll just take you to this
chat gpt thing gpt click on this i'll simply say try chat gpt this is how we go to the chat gpt right google
search for chat gpt click on the first link open [Link] chat gpt page you will go and click on this button
you'll get this new chart thing and you see here there is uh you have to type something here what is
there something that you want to type here something is not nothing but whatever you want to learn
let's say i want to learn something about uh you know
smoke testing. I can ask chargept what is smoke testing? If you are learning software testing, chargept is
helping you, okay? You don't have to do complete rnd here and there and, you know, and waste your
time. Rather, you come to chargept and, you know, instead of googling for the same question, you can
type chargept and it will give you a proper response here. You see, a concluded answer response will be
coming here. What is smoke testing? Let's see. smoke testing is a preliminary level of testing that is
performed on software application or system to verify the critical functionalities of the system are
working as expected without going into the details of the individual features. Comes from the idea of
checking whether the system can survive a smoke test without catching the fire it can handle basic
function without crashing you see a lot of text has come, but you know as a beginner, right, I don't know
if i go through this, I'm not understanding it.
So what i will do is like can you, I'll ask chargpt uh can you make it uh easier and simpler for me to,
simpler for me to understand? This kind of stuff you cannot do outside right charge up to whatever chat
chat gpt is doing here for you. Whatever the answer it gave, it's already right, but you know, I wanted to
make it even more simpler and understandable, okay? Sure, smoke testing is a type of testing that
checks whether the most important parts of the software application or system are working properly. It
is a quick and basic test that is done to ensure system is stable enough to perform more thorough
testing. The goal of the smoke testing is to identify any major issues or errors that might prevent further
testing.
Without smoke testing passing, you will go for further testing or development. Think of it as a quick
check to make sure the system is not going to catch fire before doing more detailed testing. I even got
not got satisfied. Let us say I want to understand what is smoke testing in a single line. Can you answer it
in a single line? an easy way. Kind of thing. Randomly, whatever you want us like chatting to a person,
right? You can keep on chatting and you know, it will get you the answer. Smoke testing is a quick check
to make sure the most important parts of a software application or system are working before doing
more detailed as you see, in the simple words, it has given us.
Okay? Then again, if you want to do some r d like uh how to perform uh explain me the step-by-step
process of smoke testing, when smoke testing, all the other questions you can ask, keep on asking and
charge gpt will generate. This way of learning is something good, right? This is one way of learning,
okay? This is one way of learning in software testing, okay? If you are learning software testing and if
you want to do lot of R&D on testing topics, right? You can do something like this, okay? And take the
help of ChatGPT to understand or learn it. Then, now, not only for learning, guys, you can learn
automation also, guys, not only human software testing or manual software testing, but also automation
testing.
Let's say I'm automating something and I'm I don't remember a command to, you know, to set the size
of the window. Okay. In Selenium, I'm automating some script using Selenium automation script I'm
writing in Selenium Java programming language. I want to know Selenium Java, how to set the size of a
window. Okay. How to customize the size of the window or how to set the size of a window. Like this, if
you type, now it will give you the answer. Okay, you don't have to break your head and google search
here and there and you know, find the answer. Rather it's you. You see, just in seconds you are getting
what you want. Okay, which command? You have to use set size command and how to write the code.
Example code also is being written here. Okay, like this you have to write. To do that, whatever the size
you are giving, that size, the browser window will be set as part of automation. Okay, write selenium
java code for login functionality of an application. Okay. Of application. This is like this. If you ask the
charge gpt to write a selenium Java, you have not, you, you want to save your time okay so you are
asking charge gpt to generate this for you so that you, you don't remember any command so it is going
to, it knows the commands and also it will, you know, generate the example code based on by looking at
the example code we will take the, whatever that is important and write your own code.
You see, that's how the time is getting saved for you. You see, it's writing everything. Web driver, driver
is called new Chrome driver. Driver dot get example login page, it's taking you directly to the login page
here. It's creating a web element for the username field. And now it's creating web element for the
password field. You see, I'm not writing any code here, right? ChatGPT is writing for me, okay? making
this as a reference, I can write my code now. Okay. So I don't have to break my head, go to rnd here and
there. You see all the comments are being given and example code is given. This is login button now
simply uh we are entering the name, entering the password, entering the, and clicking on the this login
button.
This is using the click command and all. Okay. Like this, it has given, you see some code. So you can keep
on asking chat gpt for whatever you are, you want. Okay. While working. So that, you know, by doing
this, you don't have to, you know, this will save your time, right? Ultimately, this code is, this example
code is given to you so that by looking at the code, you can write your code and, you know, that will
definitely save the, and it's giving you the explanation also for each and every statement that it has
written here, okay? If you are the beginner in Selenium automation or something, right, you can use
ChatGPT while learning, okay, as an assistant so that whenever you are doing some mistake, right, or
you can paste your code.
If you have written a wrong code and, you know, you want to find out what is the wrong ok let's write a
statement here in selenium java let's say web driver, driver is equal to new new galaxy which is not
there. Galaxy driver, galaxy driver is not there because intentionally i am giving this. Is giving error like
this if I write it will tell me what is wrong in this particular statement. This is a selenium java statement
assume that which is intentionally I kept galaxy driver which is not there. You see galaxy driver is not an
inbuilt driver in selenium therefore, attempting to create a web driver object using galaxy driver will
result there is no galaxy driver in selenium it came out of the thing for me.
Just I wanted to write some invalid code here. So, I am writing here you see now it is explaining how to
create this, uh, how to write this statement in a proper way it will explain you see with example, it's
giving. And whenever, when working with selenium automation or anything, right? you got some errors.
You are not able to understand what's going wrong. Then type your problem here. It will, it will tell you
the solution. You can keep on asking, asking, uh, you know, if the questions based on your intuition and
all, right. You can keep on asking and you will get, uh, Keep on asking and you'll get the solution, proper
solution, okay? You have to take the help of ChatGPT, okay?
Like that. You have to do a conversation with ChatGPT until you get the proper answer. Troubleshooting
is also very easy, guys. I have done that. So, to get to a solution, sometimes when you write some
Selenium automation code, right, some things may not work for you guys, okay? You'll get a lot of errors
and you'll break your head why these errors are coming. In that situation, right, you can keep on asking
ChatGPT here, right? You can take the help of ChatGPT and figure it. figuring out the actual problem
okay that that is causing that prob errors and all those stuff. Okay. So like that, you see, it gave a lot of
examples here. Like this, you can use chat gpt while learning guys.
Okay. Now writing automation code. I just now wrote the automation code, right? I asked for chat gpt to
write the selenium java automation code for login functionality of the play it has written the code like
that. You can do for many things. Now, the next thing is you can also use chat GPT. for generating the
test cases. Let's say I want to generate the test cases for search functionality. Let's say this is that. So I'm
a software tester. I need to, I'm going to write some test cases for testing the search functionality. So if I
keep on thinking my side only, right, you know, if I think by myself, I will take a lot of time in generating
the ideas for this, you know, search functionality.
So what I'm going to do is I'm going to ask RGPT to generate test cases for me. Okay. I don't want to
waste the time. I am very good with you know creating the test cases, but still I want to take the help of
ChartGPT in just to save my time generate test cases for search functionality like this generate test cases
for search functionality. It will generate a lot of test case on the top of the repair if it has not generated
something right you can add it out from your side. work let the chat GPT do so that lot of basic basic test
cases, right? Will be given by chat GPT. Whatever the chat GPT is not generating for you, you can add it
by your own.
At least some amount of time will be saved right and there is a possibility that whatever the test cases
that are generated by chat GPT may, you may not be able you may not thought of adding it. Okay. So
your testing will become more efficient. If more test cases are there, more better, the application you
will be testing in different ways and there is a possibility of identifying more defects, right? So, testing
will become efficient in that manner. It is working like a checklist for you now. So, these are the test
cases it is saying. I am not saying only 10 test cases, but I want around 50 test cases, 50 more test cases
let us say. Sure, you see it is keeping on, you see it understands the previous question it can understand
and now it is generating.
Let us see whether it will generate or not, I do not know, but let us see. because it is a bone to the data
that it has okay you are asking for 50 but it may not have 50 right always so it will generate as much as
possible but it's at least trying that you see all these are the days verify the search functionality returns
no results in the search query is empty randomly here and there i'm reading can handle duplicate such
terms and still provide relevant results some test case are coming let's see whether it can generate
around 50 apart from the above 10 this 10 may be the major ones Okay. So like this, you see that chat
GPT is generating the test cases for you, but you go, you know, you cannot directly copy paste this test
cases guys.
Okay. You, because chat GPT is not, doesn't have any intuition or it cannot, you know, think according to
the context or, you know, it may not be so creative as you are. Right. So there's a possibility that chat
GPT may generate some false information. Improper, uh, you know, incorrect kind of test cases. So
ultimately it's going to save your time, but you cannot blindly trust chat gpt here just and read this
statement. And if we, if you feel that you also feel that okay this test case is correct only then add the
test case into your document. Okay. So ultimately you are the one who you see it's, it has entered only
33 weeks. I told you, right. If it doesn't have more, right.
We'll stop there. Okay. It is bound to its data guys. Okay. Whatever it is trained on, it will give you.
nothing more than that. Okay. If it is stopping or it, you see, sometimes it happens where it will not give
you the expected 50 you see stop that 33 up to 33, it went. And after that it's it's kind of struck. Like
that, it will be there. Don't completely depend on charge gpt guys okay charge gpt is there here to help
you in saving your time. Okay. Wherever you feel that there's a possibility for charge gpt to save your
time, you can use that uh then defect heuristics. defect heuristics you see uh let's say heuristic means
what? Using your past experience, you are testing let's say testing heuristics let's say based on your past
experience uh you see something and you can you can decide whether there is a problem in this or
something, okay?
You see, let's say, I'll take a small example, guys, okay? Let's say there is a vegetable market and uh for
the first time, we went to the vegetable market uh is there a possibility that uh you You, you bring
home, you know, uh, you bring home something that is not a good one. Okay. Then you bring home
some vegetables from that market but since you are the beginner to the market, right. You will bring
some vegetables, which are not in a good condition that may happen. But let's say you, you visit the
market every week or something, and you are very good at that. Okay. Then you go to the market, you
know, that, okay. What problems the vegetables will have? and when you are selecting the vegetables
or purchasing the vegetables, you will check in all the ways like, okay, this item, this particular vegetable
should have so and so quality so that, uh, uh, so that to decide that it's in a good condition.
That you know right same thing here also guys so same thing here also chat i mean without chat gpt we
if we have to, you know, if you are given some application functionality for testing, let's say login
functionality, if you already have tested some other application for login functionality of another
application, then you may have already have some, uh, heuristics in your mind. Okay. Heuristics means
some learning from the previous application, like what kind of defects may come in the login
functionality. You can apply that heuristics to find the similar kind of defects in the new application that
is a new application login functionality that is given for your test. Okay. What's the advantage of
heuristics? You don't have to waste your time right you
You already have some, you know, checklist in your mind because you already have some experience of
testing that login functionality in the previous application. Now, in the current application also, you'll
apply the same test cases or testing heuristics there to find defects quickly. Now, what I say, let's give
this defect heuristics task to, apart from having our own heuristics as human beings, from our previous
experience, whatever the testing heuristics of the login functionality, whatever the functionality we
have, let's take an additional help from the chat GPT. Okay. Can you generate heuristics for finding
effects in login functionality like that? I'll ask something. Let's see what it'll do. Let's refresh here.
Sometimes, you know, chat gpt will not be able to just refresh. Can you generate generate heuristics for
identifying defects quickly in login functionality. Functionality like this you write one line and you know
certainly here are some heuristics for identifying defects quickly in login functionality verify the login
credentials. You see it is giving all the ideas using which you can find the defects quickly ok. Check for
session management, check for error handling, test for user roles, test for password verify security
measures. You see all the different crazy ideas it is giving you. Using these ideas, there is a possibility
that you may find some defects. So, these are heuristics of ChartGPT, guys. But apart from these
heuristics, we also have our own experience heuristics using which also will add this list to our list and
finally find more defects. This will make the testing more efficient and it will save a lot of time for us.
And is there any other stuff for which I can use ChartGPT? you see email email templates anything else
anything you can literally use anything can you generate generate an email template for sending testing
software testing results software testing results to my client at the end of the day. Okay. My client name
is okay. My client name is just give some, let's say Charlie, Charlie T or something. And my name is and
press enter. sure here is an email template for sending software test and that is subject daily software
testing report per date. You see, it's giving you the email subject. You see how efficient you can use,
guys, okay? Yeah, Charlie, I hope this email finds you well. I am the software testing specialist on your
project, working to provide you uh with the today's software testing report.
Throughout the day, our team has been working diligently to test the software. You see how better it is
writing for you. You don't have to break your head anymore, okay? Communication also very good.
identify any potential issues or defects. We have tested various modules, including list modules, found
defect found if any. All we are pleased to report that the software is functioning well and meets the
expected. Please, if you want to write for different context, right, you can write a statement here. Okay.
So that you got this many defects. Can you change the template for me? Like it will generate another
template, which according to your needs. Okay. Give the instructions to jargbt to generate this email
template in your way you want.
Okay. like that and many more guys, many more. So what is the ultimate conclusion here is can chat gpt
replace human software testing? After all this explanation, you can clearly state that chat gpt is not
going to replace the human software testing or software testers. Okay. So then what, what is the
advantage of using chat gpt as part of software testing is it is going to power your testing strategy. Okay.
Your testing, it's going to power your testing. testing work or testing strategy, whatever you say in all
this kind of ways you can learn it. Okay. Faster way of learning. It's enhancing. It's helping you in writing
your automation code in a faster way. Uh, generating the test case, you know, doing work, uh, work in a
faster way, an efficient way by saving the time heuristics email templates, many more.
These are few ways guys, you can invent more ways. Okay. for now i invented these ways or i identified
these ways You can identify few more ways, ok. So, keep using ChartGPT, keep it side by side while you
are performing software testing wherever you feel that ok, let us ask ChartGPT, go and ask ChartGPT
and observe that it is going to save your time and help you in making your work efficient, ok. Ultimately,
we are the ones who have to get the work given, get the results given by ChartGPT, ok. It cannot
completely replace domain software testing or software testers. So, that is all for this session. Hope you
got the answer. for CanChat GPT Replace Women software testing. Hope you've already got relieved
now by this time, by the end of this session.