更新时间:2023-02-04 23:36:28
尝试添加 SET NOCOUNT ON
触发器
这个错误看起来不像SQL错误,我在猜测客户端代码被触发器中的第二次更新弄糊涂了。
编辑:这个错误可能是由SSMS中的数据网格视图造成的。
这不是一个SQL消息,因为我认为:这是一个SSMS是一个愚蠢的消息
看到这些都说学习写SQL
说的是,知识库文章 a>关于SQL Server 2005中的错误...
I'm using insert-/update triggers to update a second table's column Price
.
The insert trigger seems to work perfectly, but when I try to change a single record in SSMS, I get an error:
The row value(s) updated or deleted either do not make the row unique or they alter multiple rows(2 rows).
This is my update-trigger:
CREATE TRIGGER [dbo].[trgUpdateMasterData] ON [dbo].[tabSparePartMasterData_Temp]
AFTER UPDATE
AS
UPDATE tabSparePart
SET Price = MD.Price
FROM tabSparePart INNER JOIN
(
SELECT inserted.[Material Number (SAP)] AS MaterialNumber, inserted.Price
FROM inserted
GROUP BY [Material Number (SAP)], inserted.Price
) MD
ON tabSparePart.SparePartName = MD.MaterialNumber
I need to group by Material-Number because there are redundant rows inserted into table tabSparePartMasterData_Temp
which i'm only using to update the Sparepart-Price in tabSparePart
. But i assumed that the group by would sort out the duplicates(Price is same for any duplicate).
It's possible that the inserted/updated records' MaterialNumber
is not available in tabSparepart
. In this case this record should be "skipped". Does the INNER JOIN
takes that into account?
Try adding SET NOCOUNT ON
to the trigger
This error doesn't look like a SQL error and I'm guessing the client code is getting confused by the 2nd update in the trigger.
Edit: this error can be caused by the data grid view in SSMS being silly.
This isn't a SQL message as I thought: it is an SSMS being stupid message
See these which all says "learn to write SQL"
Saying that, there is a KB article about a bug in SQL Server 2005...