Articles → SQL SERVER → Insert Data In View In SQL Server

Insert Data In View In SQL Server






Creating Table




Picture showing the design view of the Employee and Designation tables
Click to Enlarge


Create A View




create view vw_Employee As 
Select 
  EmployeeName, 
  [Description] 
From 
  Employee E 
  inner join Designation D On E.Designation = D.[Description]



Create An Instead Of Trigger


CREATE TRIGGER TRG_EMPLOYEE_DESIGNATION ON vw_Employee INSTEAD OF INSERT AS BEGIN Insert into Employee (EmployeeName) 
select 
  EmployeeName 
From 
  Inserted Insert into Designation 
select 
  [Description] 
From 
  Inserted END



Insert Data Into View




insert into vw_Employee 
values 
  ('Gyan', 'Manager')



Output




Picture showing the output of Inserting data in view in SQL server
Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Thursday, June 18, 2015

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250