Update Command
Update Command
Update Command
“Update” Command:
Is a DML Command.
It is a used to update [modify] the records.
It can be also used to perform calculations and store the result in
tables.
Using this command we can update single record, a set of records &
all records.
Syntax:
Update <Table_Name>
Set <column-1>=<value-1>[, <column-2>=<value-2>, ......... ]
[Where <Condition>];
Example:
Update emp set sal=4000,comm=500 where empno=7900;
Updating job value as manager and sal as 5000 to the employee whose
empno is 7369 [Updating multiple field values of a record]:
SQL> Update emp set sal=5000, job='MANAGER' where empno=7369;
Output:
1 row updated.
Output:
4 rows updated.
SQL> /
Enter value for sal: 3000
Enter value for empno: 7934
Output:
old 1: Update emp set sal=&sal where empno=&empno
new 1: Update emp set sal=3000 where empno=7934
1 row updated.
Increasing 10% sal to the employees whose name is started with 's':
Update emp set sal=sal+sal*0.1 where ename like 'S%';
Increasing 10% sal to the employees who have greater than 40 years
experience:
Update emp set sal=sal+sal*0.1 where (sysdate-hiredate)/365>40;
Example-2:
Create a Table with following Structure & Insert the records. Then
calculate total and average marks:
Student
StdID SName M1 M2 M3 Total Avrg
1001 Ravi 40 80 60
1002 Sravan 66 44 77
Output:
Table created.
Output:
1 row created.
Calculating Total:
SQL> Update Student Set Total=M1+M2+M3;
Output:
2 rows updated.
Output:
2 rows updated.
Output:
Table created.
Inserting Records:
SQL> Insert into Employee(Empno,Ename,Job,BasicSal)
values(1001,'Sai','CLERK',4000);
Output:
1 row created.
Output:
1 row created.
Output:
2 rows updated.
Output:
EMPNO ENAME JOB BASICSAL TA DA HRA GROSS