Wednesday 16 October 2013

10. Create a trigger named Emp_Nested_Trg on the EmployeeDetails table for an insert operation. This trigger should ensure that a new record being inserted into the EmployeeDetails table has a matching record in the DeptDetails table. Otherwise, the insert operation is rolled back.

create trigger Emp_Nestes_Trg
on EmployeeDetails After Insert
as
Begin
Declare @OptNo int
select @OptNo=OptNo from Inserted
If not Exists(select * from DeptDetails
Where DeptNo=@deptNo)
Print 'The specified DeptNo does not exist.'
Rollback
end

No comments:

Post a Comment