我有以下 SQL 触发器:
ALTER TRIGGER [dbo].[DIENSTLEISTUNG_Update]
ON [dbo].[DIENSTLEISTUNG]
INSTEAD OF UPDATE
AS
BEGIN
SET NOCOUNT ON;
INSERT INTO [DIENSTLEISTUNG]
(DESCRIPTION, QUANTITY,
PRICE, AZ_MO, AZ_DI,AZ_MI,AZ_DO,AZ_FR,
AZ_SA,AZ_SO,DIENSTLEISTUNGSART_ID,
UPDATE_USER, UPDATE_DATE,
PERMISSIONS, KONTRAKTPOSITION,ITEMNUMBER,
PRIORITY, VALID)
SELECT DESCRIPTION, QUANTITY, PRICE AZ_MO, AZ_DI,AZ_MI,AZ_DO,AZ_FR,
AZ_SA,AZ_SO,SERVICETYPE_ID, UPDATE_USER,GETDATE(),
PERMISSIONS, KONTRAKTPOSITION,ITEMNUMBER, PRIORITY, 'Y',VALID
FROM INSERTED
UPDATE SERVICE
SET VALID = 'N'
FROM SERVICE
INNER JOIN INSERTED ON INSERTED.ID = SERVICE.ID
SET NOCOUNT OFF;
END
如果原始行发生更改,触发器会复制具有新 ID 的整行。到现在为止还挺好。我希望触发器仅在更新PRICE
或DESCRIPTION
更新时创建一个新行。如果我对PRIORITY
orITEMNUMER
或其他列进行更新,则触发器应该只更新行,而不是创建新行。
我怎样才能做到这一点?