用触发器替换原来的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
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