create table employee(
ID int,
name nvarchar (10),
salary int )
GO
create table job(
ID int,
title nvarchar (10),
averageSalary int)
GO
insert into employee (ID, name, salary) values (1, 'Jason', 1234)
GO
(1 rows affected)
insert into employee (ID, name, salary) values (2, 'Robert', 4321)
GO
(1 rows affected)
insert into employee (ID, name, salary) values (3, 'Celia', 5432)
GO
(1 rows affected)
insert into employee (ID, name, salary) values (4, 'Linda', 3456)
GO
(1 rows affected)
insert into employee (ID, name, salary) values (5, 'David', 7654)
GO
(1 rows affected)
insert into employee (ID, name, salary) values (6, 'James', 4567)
GO
(1 rows affected)
insert into employee (ID, name, salary) values (7, 'Alison', 8744)
GO
(1 rows affected)
insert into employee (ID, name, salary) values (8, 'Chris', 9875)
GO
(1 rows affected)
insert into employee (ID, name, salary) values (9, 'Mary', 2345)
GO
(1 rows affected)
insert into job(ID, title, averageSalary) values(1,'Developer',3000)
GO
(1 rows affected)
insert into job(ID, title, averageSalary) values(2,'Tester', 4000)
GO
(1 rows affected)
insert into job(ID, title, averageSalary) values(3,'Designer', 5000)
GO
(1 rows affected)
insert into job(ID, title, averageSalary) values(4,'Programmer', 6000)
GO
(1 rows affected)
select * from employee;
GO
ID name salary
----------- ---------- -----------
1 Jason 1234
2 Robert 4321
3 Celia 5432
4 Linda 3456
5 David 7654
6 James 4567
7 Alison 8744
8 Chris 9875
9 Mary 2345
(9 rows affected)
select * from job;
GO
ID title averageSalary
----------- ---------- -------------
1 Developer 3000
2 Tester 4000
3 Designer 5000
4 Programmer 6000
(4 rows affected)
-- Updating Rows Based on Multiple Tables
UPDATE Employee
SET Salary = 4000
FROM Employee INNER JOIN Job
ON Employee.ID = Job.ID
GO
(4 rows affected)
select * from employee
GO
ID name salary
----------- ---------- -----------
1 Jason 4000
2 Robert 4000
3 Celia 4000
4 Linda 4000
5 David 7654
6 James 4567
7 Alison 8744
8 Chris 9875
9 Mary 2345
(9 rows affected)
drop table employee;
drop table job;
GOIn this code you will learn to update rows based on multiple tables in SQL Server.