SQL Server: Update columns or fields in SQL Server | SQL Update command.


--Updating table fields

--Check the Initial state of the table before updating…
select * from tabEmployee

--Update Request: 
--Update employee Department to 'Training' whose EmpID is 1005
Update tabEmployee set Department='Training' where EmpID=1005
--(1 row affected)

--Check output
select * from tabEmployee where EmpID=1005

--Update Request: 
--Update employee Department to 'Training' whose EmpName is 'Asrafi Basha'
Update tabEmployee set Designation='Business Trainer' where EmpName='Asrafi Basha'
--(1 row affected)

--Check output
select * from tabEmployee where EmpName='Asrafi Basha'

--Update Request: 
--Double the Salary of all Behavioral Trainers
update tabEmployee set Salary=Salary*2 
where Designation='Behavioral Trainer'
--(4 rows affected)

--Check output
select * from tabEmployee where Designation='Behavioral Trainer'


--Update Request: 
--Increase 50% of the Salary of all Technical Trainers working in the Development Department
update tabEmployee set Salary=Salary+(salary*0.5) where Department='Development' and Designation='Technical Trainer'
--(2 rows affected)


--Check output
select * from tabEmployee 
where Department='Development' and Designation='Technical Trainer'

--Update Request: 
--Promote the "Business Trainer"
--as HR Manager to the "HR Department" and fix salary 80000

update tabEmployee
set Department='HR Department',Designation='HR Manager',Salary=80000
where Designation='Business Trainer'
--(1 row affected)

--Check output

select * from tabEmployee where Department='HR Department'

No comments:

Post a Comment