Update command
This command helps us to modify the existing data in the table. Helps us to perform calculations.
Update command can be used in two ways
(i) to modify all the records
(ii) to modify the selected records
(i) to modify all the records
Syntax:
update tablename
set col1=exp1, col2=exp2, col3=exp3;
Example Queries:
1. To increase the salary of all the employees by Rs.2000/-
Sol:
Update emp Set sal=sal+2000;
2. To increase the salary by 10 %.
Sol:
Update emp set sal=sal+.10*sal;
3. Increase the rate of all the products by 2.5 %
Sol:
Update product set rate=rate+.025*rate;
(ii). to modify the selected records
Syntax:
update tablename
set col1=exp1, col2=exp2, col3=exp3
where condition;
Examples queries:
1. increase the salary of all managers by rs.5000
Sol:
update emp set sal=sal+5000 where desig=’manager’;
2. Increase the salary of all managers and programmers working in either production or sales department by 5 %.
Sol:
Update emp set sal=sal+.05*sal where (desig=’manager’ or desig=’programmer’) and (deptname=’production’ or deptname=’sales’);
3. Increase the marks of eng by 3 of all the students who have got per>=60.
Sol:
Update student set eng=eng+3 where per>=60;