私は1行だけを更新してもうまく動作する更新トリガを書いていますが、複数の行を更新するとエラーが発生します。複数行更新のトリガを書き込む方法は?
エラー:ここ
Msg 512, Level 16, State 1, Procedure Sale_OnUpdate, Line 14 Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
は私が複数の行のために働いて、それを作るために何をすべき変化をトリガー
ALTER TRIGGER [dbo].[Sale_OnUpdate] ON [dbo].[Sale]
AFTER Update
AS
Declare @ID as decimal
Declare @User as varchar(250)
Declare @Status as varchar(250)
set @ID = (Select ID from Inserted)
set @User = (Select UpdatedByUser from Inserted)
set @Status = Isnull((Select Status from Inserted),'')
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
INSERT INTO [dbo].[Log]
(
[RecordID]
,[Date]
,[Time]
,[UserName]
,[TableName]
,[Action]
)
VALUES
(
@ID
,GetDate()
,GetDate()
,@User
,'Sale'
,'Update,' + @Status
)
END
です。
しかし、これら3つのフィールド(ID、User、Status)をログに記録します。 –
@MujassirNasir:あなたの質問ではありませんでした。 –
私はこれを試しましたが、私はそれが動作する知っているが、私はすべてのアクションを記録するトリガを書きたい。 –