gpt4 book ai didi

SQL 服务器 : Insert row with trigger after Insert

转载 作者:行者123 更新时间:2023-12-04 03:19:59 27 4
gpt4 key购买 nike

每当使用触发器插入行时,我都试图将另一行插入表中,但收到以下错误消息:

The target table 'EDDSDBO.Redaction' of the DML statement cannot have any enabled triggers if the statement contains an OUTPUT clause without INTO clause.

如能提供解决方案,我们将不胜感激。

通过阅读下面的链接,我的代码目前如下

Cannot use UPDATE with OUTPUT clause when a trigger is on the table

SQL Server Helper workaround

代码:

ALTER TRIGGER [EDDSDBO].[AddLabel]
ON [EDDSDBO].[Redaction]
AFTER INSERT
AS
BEGIN
DECLARE @T TABLE (
[FileGuid] VARCHAR, [X] INT, [Y] INT, [Width] INT, [Height] INT
)

INSERT INTO [Redaction] [FileGuid],[X],[Y],[Width],[Height]
OUTPUT [inserted].[FileGuid], [inserted].[X], [inserted].[Y],
[inserted].[Width], [inserted].[Height]
INTO @T
SELECT
[inserted].[FileGuid], [inserted].[X], [inserted].[Y], 70, 35
FROM
inserted

SELECT *
FROM @T
END

在阅读所描述的链接之前,INSERT 代码最初如下:

INSERT INTO [Redaction] 
[FileGuid],[X],[Y],[Width],[Height]
SELECT TOP 1
[FileGuid], [X], [Y], 70, 35
FROM [Redaction] AS r1
ORDER BY [ID] DESC

更新:事实证明,kCura 的 Relativity 平台不允许使用触发器插入,所以这是徒劳的...

最佳答案

由于您在触发器中,触发器本身已经定义了 Inserted 伪表供其使用。

不能将它与OUTPUT 子句需要的Inserted 别名混合使用。

因此,您不能在触发器内的语句中使用OUTPUT 子句。

此外:触发器应该安静地完成它们的工作并且不产生任何结果集!

更新:INSERT正确语法(即 easily found on MSDN ...)是:

INSERT INTO [Redaction] ([FileGuid], [X], [Y], [Width], [Height])
SELECT TOP 1
[FileGuid], [X], [Y], 70, 35
FROM
[Redaction] AS r1
ORDER BY
[ID] DESC

您需要在 INSERT INTO 行中的列列表周围添加括号

关于SQL 服务器 : Insert row with trigger after Insert,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38973000/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com