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