0:00
what is going on everybody my name is
0:02
Alex Freiburg and today we're gonna be
0:04
looking at updating and deleting data in
0:06
a table now what's the difference
0:08
between inserting data into a table and
0:10
updating data insert into is going to
0:13
create a new row in your table while
0:15
updating is gonna alter a pre-existing
0:17
row while the leading is going to
0:20
specify what rows you want to remove
0:22
from your table so let's get going with
0:25
the updating so down here Holly flax
0:28
does not have an employee ID age or
0:31
gender now we want to update this table
0:33
to give her that information so let's do
0:36
update now we need to specify what table
0:39
we're gonna be hitting off of so let's
0:40
do sequel tutorial TVO dot employee
0:44
demographics so now we're gonna use
0:45
something called set and set is gonna
0:47
specify what column and what value you
0:50
actually want to insert into that cell
0:52
so let's set her employee ID equal to
0:58
and it's going to be 1012 and we have to
1:02
specify which one to do this to because
1:04
if we ran just this is gonna set every
1:07
single employee ID to one thousand
1:10
twelve because we haven't specified that
1:11
we only want Holly flax is row to be
1:13
updated so now we have to specify where
1:17
first-name is equal to Holly and
1:24
lastname is equal to flex so now let's
1:30
run this and see what we get
1:34
so one row has been affected let's see
1:38
what we got and there we go as you can
1:41
see the employee ID was updated exactly
1:43
how we specified it right here so we
1:46
also want to update age and gender and
1:48
let's do that in the same query so let's
1:51
set the age equal to thirty one and
1:54
instead of using and we actually need to
1:57
use a comma so let's say age equal to
2:00
thirty one comma gender is going to be
2:03
equal to female and let's run this and
2:08
see we get there you go now let's look
2:11
at our table
2:13
and as you can see it was updated to 31
2:16
and female so very easy very easy to
2:20
specify what you want oftentimes tables
2:23
like this will have a unique key like
2:24
employee ID is our unique key in this
2:27
table so I could easily just say where
2:30
the employee ID is equal to and then you
2:34
know 1012 so it's an easy way to specify
2:37
what employee you're trying to update so
2:39
now let's look at the delete statement
2:41
the delete statement is going to remove
2:42
an entire row from our table so let's do
2:46
delete and we actually need to say from
2:50
and we have to specify what table we
2:52
want to be removing this information
2:53
from so let's do sequel tutorial dot DV
2:56
dot employee demographics and now we
3:00
need to specify what row we want to
3:02
remove so let's do where employee ID is
3:07
equal to and let's choose a completely
3:09
random employee ID 1005 so let's run
3:14
this and see what happens
3:16
so one rows affected let's look at our
3:21
table and as you can see one thousand
3:24
five is now gone now you have to be very
3:27
careful when you use the delete
3:28
statement because once you run it you
3:30
cannot get that data back there's no way
3:32
to reverse a delete statement so if I
3:35
had gotten rid of this wear statement
3:36
and I ran this it would delete
3:38
everything from the entire table and you
3:39
could not get that data back so a little
3:41
trick that I use before I actually run a
3:44
delete statement is I make it a select
3:46
statement because you're gonna select
3:48
everything where the employee ID is
3:52
equal to let's just do in that form and
3:55
now when you run this you were gonna see
3:57
exactly what you will be deleting and
4:00
now we know that Angela Martin that
4:02
entire row is gonna be gone if I haven't
4:05
done that and I just went like this and
4:07
I wrote delete and I only had this
4:09
running I would not know that this
4:11
information is gonna be the only one
4:12
that's gone maybe I made a mistake down
4:14
here maybe I accidentally put something
4:16
in - that wasn't supposed to be in there
4:17
and now I'm deleting much more than I
4:19
thought I was actually gonna delete so
4:22
using the selects naming can be a very
4:24
good safeguard against
4:25
so then to lead to leading data that you
4:27
do not want to delete so that is update
4:29
and delete thank you guys so much for
4:31
watching I really appreciate it if you
4:33
liked this video be sure to subscribe
4:34
below and I'll see you in the next video