Member-only story
SQL Server— Update table using Inner join in SQL
We always try to keep normalization in our database and maintain table relationship for each record as possible. To maintain normalization, we always put our records in more than two tables by making relationship between them which are highly tide up mostly on primary and foreign key relationship.
Example: In an organization, based on the performance, some employees got the appraisal but some of them did not get any appraisal. Now, system needs to update the salary in employee master only for those employees who got the appraisal.
Note: We can only update 1 table at a time by using Update command.
We have two tables structure to store the above scenario such as:
USE tempdb;GO — — — create temp table to store employees informationCREATE TABLE [dbo].[EmployeeMaster]([EmpId] [int] IDENTITY(100,1) NOT NULL,[EmpName] [varchar](50) NOT NULL,[EmpSalary] [int] NOT NULL,[EmpAge] [int] NOT NULL,[EmpStatus] [bit] NULL) ON [PRIMARY] — — — create another temp table to store employees appraisal