SQL UPDATE

Write SQL UPDATE queries.

The UPDATE statement is used to modify the existing records in a table.

Example


Table: Employee                             
+----+-------+--------+--------------+      
| Id | Name  | Salary | DepartmentId |      
+----+-------+--------+--------------+      
1  | Ram   | 85000  | 1            |      
2  | Henry | 80000  | 2            |      
3  | Sam   | 60000  | 2            |      
4  | Shyam | 60000  | 1            |
5  | Geeta | 90000  | 1            |
6  | Sheet | 90000  | 1            |
7  | Leela | 80000  | 1            |
8  | Geeta | 70000  | 1            |
+----+-------+--------+--------------+

Approach

Mysql/ Oracle: Update the first Employee (ID=1) name and salary.


UPDATE Employee  SET NAME ='RAM SINGH', Salary='90000' WHERE ID=1;

Mysql/ Oracle: Update the multiple records (rows) (Update salary of every employee of department 1 )

UPDATE Employee  SET  Salary='90000' WHERE DepartmentId=1;


No comments:

Post a Comment