hi guys this is Mina and welcome back to my channel. i want to introduce you to SQL data
manipulation languages these are statements used to modify, retrieve, store and delete data within
a table. They include the update select insert and delete statements. Actually we've already
looked at the insert and delete statements in my previous videos, so feel free to follow
these links in the description section to watch them if you have not already done so
today we will be looking at the update statement it is used to modify existing data in a table
the syntax is, you type out the word update and then the table you want to update
type out the word set and which column do you want to update, because! what value do you want
to replace in that column, you can do that for multiple columns. The first part of the update
statement will update all the records in the table unless you provide a condition
using the where clause. Let's move on to our SQL server management studio and try this out
once you launch your SQL server management studio enter your credentials and click on connect
in the object explorer, i'll go to databases and these are all the databases that i have
in my SQL server management studio. Today will be we will be working with the exploration data
that we imported from our excel spreadsheet if you want to know how we imported this database
feel free to watch my previous video. So the first thing i will do is to click on new query and
select this database exploration data i will paste the syntax for the update statement here so we can
refer to it at any time okay so in the exploration database let's see the tables that we have. we are
going to be working with the employees table so let's see what we have in our employees table
these are all the data in our employees table now let's start updating some of these records
remember update statement is used to modify data or records in a table this is our employees table
and we are going to update some of these records okay the syntax says that update
table name and set column equals value. let's try it out so update the table is employees table
set what columns do we have, as you can see we have employee id first name
last name, email, title, gender shift and the number of hours. So set for instance first name
equals Anita. This statement means that i want to change all the names under first name column to
Anita. In sql and anytime you type a string value you have to put them in a single quote
otherwise you're going to get an error. Let's see without these strings
invalid column name Anita so if you put it in a single quote that should work and we are expecting
this query to change all the first names to Anita before i execute let's look at our table again
under first name column, we have several different names so right now i'm going to execute this
command and i expect that all these names should change to Anita okay, 10 rows affected
now let's select our employees tables again. see all the first names have been changed to
Anita, this is what you get if you update a table without the where clause so
let's make some changes this time adding the where condition if we say where last name
equals Douglas
okay so let's set first name equals
Mike where last name equals Douglas. It means we want to change first name to Mike
if we execute this command but because of this where clause where last name equals Douglas, so
where last name equals Douglas means that this particular first name is what we want to change
so we are changing this Anita to Mike because the last name is Douglas, where last name because
Douglas. let's execute this command one row affected this time so let's select
and see. See only the first row with the last name Douglas has been updated
it is always advisable to use the unique column or the primary key in your where statement
let me show you what i mean, so i'm going to change first name to mike where employee id
equals EM1. this way we are sure that no other column has this
same employee id so let's execute this command and see
one rule affected. Again if we select from our employees table we should see that only the second
record has been changed to Mike. so this is how you update records or data within a table in sql
server management studio. Thank you for watching this video and see you on my next one, bye bye