Sitemap

SQL UPDATE STATEMENT

2 min readApr 4, 2023

--

UPDATING RECORDS

Press enter or click to view image in full size

The update statement is used to update or change records that match a specified criteria. This is accomplished by carefully constructing a where clause.

update "tablename"
set column1 = value1, column2 = value2, ...
where condition;

Note: The WHERE clause specifies which record(s) that should be updated. If you don’t use WHERE clause, all records in the table will be updated!!!

Get Akheelmohammad’s stories in your inbox

Join Medium for free to get updates from this writer.

Examples:

update employee
set wage= wage+623
where name="Akheel";
update fruits
set price=price+100
where breed='NANs' and category='W';
update student
set last_name = 'Mohammad'
where last_name = 'Mohamd';

Update statement exercises

1.shaik Tabu just got married to Md Akheel. She has requested that her first name be updated to Md.

update myemployees   
set firstname = 'Md'
where firstname = 'shaik' and lastname = 'Tabu';

2.Akheel’s birthday is today, add 1 to his age.

update myemployees   
set age = age+1
where name = 'Akheel'

3.All secretaries are now called “Administrative Assistant”. Update all titles accordingly.

update myemployees
set title = 'Administrative Assistant'
where title = 'Secretary';
select * from myemployees;

4.Everyone that’s making under 30000 are to receive a 3500 a year raise.

update myemployees
set salary = salary + 3500
where salary < 30000;
select * from myemployees;

5.Everyone that’s making over 33500 are to receive a 4500 a year raise.

update myemployees   
set salary = salary + 4500
where salary > 33500;

6.All “Doctor” titles are now promoted to “Senior Doctors”.

update myemployees   
set title = 'Doctors'
where title = 'Senior Doctors';

7.All “Hyderabad” rows in city are now named to “Hyderabad — ”.

update myemployees   
set title = 'Hyderabad'
where title = 'Hyderabad--';

8.Update ContactName and City of CustomerID=1 with your name and city

UPDATE Customers
SET ContactName = 'Akheel', City= 'Hyderabad'
WHERE CustomerID = 1;

--

--