Wednesday, May 7, 2008

Trigger

*************Insert Trigger*******************
USE [CustomerCare]
GO
/****** Object: Trigger [tri_ClientInqDtl] Script Date: 04/26/2008 12:06:01 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TRIGGER [tri_ClientInqDtl]
on [dbo].[ClientInqDtl]
AFTER INSERT
AS
Declare @ClientPrdId int,
@EmployeeId int,
@ClientInquiryDtl int

select @ClientInquiryDtl=ClientInquiryDtl from inserted
select @ClientPrdId=ClientPrdId from inserted
select @EmployeeId=EmployeeId from ClientPrdMaster where ClientPrdId=@ClientPrdId


BEGIN
Update ClientInqDtl set EmployeeId=@EmployeeId where ClientInquiryDtl=@ClientInquiryDtl
End
***************Delete Trigger*********************
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TRIGGER [tri_DeletePrdVersion]
ON [dbo].[ProductMaster]
AFTER DELETE
AS
Declare @ProductId int

select @ProductId=ProductId from Deleted
BEGIN
delete ProductVersion where Productid=@ProductId
END