用触发器替换原来的insert

alter TRIGGER InsertEnterprise
   
ON T_Enterprise
  instead 
of INSERT 
AS 
BEGIN
    
SET NOCOUNT ON;
    
SET QUOTED_IDENTIFIER ON;
    
declare @TempId int
    
insert into fieldweb.dbo.enterpriseinfo(companyname,ServicesType,Location
    ,E_Code,EnterpriseNO)
    
select companyname,industryid,address,postcode,enterprisecode from inserted
    
select  @TempId=@@identity

    
INSERT INTO [CRM].[dbo].[T_Enterprise]
           (
[CompanyName]
           ,
[EnterpriseCode]
           ,
[WebSiteId]
           ,
[IndustryId]
           ,
[IndustryName]
           ,
[NatrueId]
           ,
[NatrueName]
           ,
[Address]
           ,
[PostCode]
           ,
[WebUrl]
           ,
[AddTime]
           ,
[Operator])
           
select
            
[CompanyName]
           ,
[EnterpriseCode]
           ,
[WebSiteId]
           ,
[IndustryId]
           ,
[IndustryName]
           ,
[NatrueId]
           ,
[NatrueName]
           ,
[Address]
           ,
[PostCode]
           ,
[WebUrl]
           ,
[AddTime]
           ,
[Operator]
            
from inserted
    
update t_enterprise set websiteid=@TempId where id=@@identity
    
END
GO
posted @ 2009-03-10 18:35  芬奇  阅读(352)  评论(0编辑  收藏  举报