我在更新触发器中有此查询
UPDATE [FSSQLPROD01].[collectionsDELETE].[dbo].[collections]
SET
Defendant_1 = i.DisplayName
, Loan_Number_1 = i.Comments
, Client = i.KS_BookName
, Date_Instructed = i.OpenDate
, Person_Responsible_name = i.ResponsibleFeeEarnerName
, Person_Responsible_Email = i.ResponsibleFeeEarnerEmail
, Person_Acting_name = i.BillingFeeEarnerName
, Person_Acting_email = i.BillingFeeEarnerEmail
, Agent_Acting_name = i.BillingFeeEarnerName
, Agent_Acting_email = i.BillingFeeEarnerEmail
, CBA_Panel_Service_Area = i.KS_ServiceCat
, HBN_Number = i.KS_ClientAcctRef
, St_George_Contact = i.KS_Instructor
FROM
[FSSQLPROD01].[collectionsDELETE].[dbo].[collections] c
INNER JOIN
Inserted i
ON
Left(c.file_number, 6) COLLATE DATABASE_DEFAULT = i.MatterNumber COLLATE DATABASE_DEFAULT
现在,Join连接在File_Number上匹配,例如70003-1但由于某些未知原因,应该更新到此行的数据已更新为一个非常随机的行614864-7
我可以继续执行触发器并尝试更新70003-1行,但我继续更新另一行614864-7
这也在链接服务器上运行,触发器位于一台与其他服务器约会的服务器上
服务器tigger位于Microsoft SQL Server 2005上 - 9.00.3042.00(X64)2007年2月10日00:59:02版权所有(c)1988-2005 Microsoft Corporation企业版(64位)在Windows NT 5.2上(Build 3790: Service Pack 2)
服务器触发器正在更新Microsoft SQL Server 2005 - 9.00.3042.00(X64)2007年2月10日00:59:02版权所有(c)1988-2005 Windows NT 5.2上的Microsoft Corporation Enterprise Edition(64位)(Build 3790: Service Pack 2)
我一直在想将服务器SP更新到SP4可能会解决问题吗?
有没有人有共鸣为什么这可能会使服务器变得更糟糕
修订
是的,我实际上硬编码了这些值并简化了它应该运行的SQL语句
DECLARE @MatterNumber as varchar(50)
SET @MatterNumber = (SELECT i.MAtternumber FRom Inserted as i) + '-1'
Print @MatterNumber
UPDATE [FSSQLPROD01].[collectionsDELETE].[dbo].[collections]
SET Loan_Number_1 = ‘123’
WHERE file_number = @MatterNumber
但是一旦我将一个声明的Varible值设置为Loan_Number_1或任何其他的columes,这就是问题开始发生的时候
DECLARE @LoanNumber as varchar(50)
SET @LoanNumber = (SELECT i.Comments FRom Inserted as i)
Print @LoanNumber
DECLARE @MatterNumber as varchar(50)
SET @MatterNumber = (SELECT i.MAtternumber FRom Inserted as i) + '-1'
Print @MatterNumber –-I print here I see 70003-1
UPDATE [FSSQLPROD01].[collectionsDELETE].[dbo].[collections]
SET Loan_Number_1 = @LoanNumber
WHERE file_number = @MatterNumber
Print @MatterNumber –-I print here I see 70003-1
答案 0 :(得分:0)
UPDATE [FSSQLPROD01].[collectionsDELETE].[dbo].[collections]
SET
Defendant_1 = i.DisplayName
, Loan_Number_1 = i.Comments
, Client = i.KS_BookName
, Date_Instructed = i.OpenDate
, Person_Responsible_name = i.ResponsibleFeeEarnerName
, Person_Responsible_Email = i.ResponsibleFeeEarnerEmail
, Person_Acting_name = i.BillingFeeEarnerName
, Person_Acting_email = i.BillingFeeEarnerEmail
, Agent_Acting_name = i.BillingFeeEarnerName
, Agent_Acting_email = i.BillingFeeEarnerEmail
, CBA_Panel_Service_Area = i.KS_ServiceCat
, HBN_Number = i.KS_ClientAcctRef
, St_George_Contact = i.KS_Instructor
FROM
Inserted i
where
Left([FSSQLPROD01].[collectionsDELETE].[dbo].[collections] .file_number, 6) COLLATE DATABASE_DEFAULT = i.MatterNumber COLLATE DATABASE_DEFAULT
答案 1 :(得分:-4)
触发器用于更新单个记录。当我们进行批量插入/更新时,它们不起作用。
因为SQL Server triggers runs only 1 time per UPDATE.
如果在单个语句中修改3000行,则触发器不会触发3000次。你的触发器只会触发一次。所以这就是它更新随机行的原因(尽管它应该是第1行)。