Wednesday 16 October 2013

09. Consider the following statement: CREATE VIEW Emp_Dept AS SELECT E.EmployeeID, E.EmpName, E.Designation, E.Salary, D.DeptNo, D.DeptName FROM EmployeeDetails E INNER JOIN DeptDetails D ON E.DeptNo=D.DeptNo A view named Emp_Dept has been created on the base tables, EmployeeDetails and DeptDetails, by using the preceding statement. John is the Database Developer with AdventureWorks Incorporation. He wants that the users should be able to insert data in the underlying base tables by using the view. He can implement the desired functionality if the insert operation affects a single table. However, the same cannot be done if multiple tables are involved. He wants to be able to insert data in both the tables with the help of a single insert statement. Help John in resolving the problem.

create trigger View_Insert_Trg
on Emp_Dept Instead of Insert
as
Begin
Insert into EmployeeDetails(EmployeeID,EMPName,
Designation, Salary,DeptNo)
select EmployeeID,EmpName,Designation,salary,DeptNo from Inserted
Insert into DeptDetails(DeptNo,DeptName)
select DeptNo,DeptName from Inserted
end

No comments:

Post a Comment