T-SQL how to create a update trigger to update a column after a row is updated?
Tag : sql , By : user107021
Date : March 29 2020, 07:55 AM
wish helps you Use this. For more information about triggers refer this link. CREATE TRIGGER Sample ON [dbo].[FileContent]
FOR UPDATE
AS
BEGIN
IF UPDATE([Content])
BEGIN
DECLARE @nFieldID AS INT
SELECT @nFieldID = [FileId] FROM INSERTED
UPDATE [dbo].[FileContent]
SET [UpdateTime] = GETDATE()
WHERE [FileId] = @nFieldID
END
END
|
Update a table when an specific column of another table is updated using trigger in SQL Server
Date : March 29 2020, 07:55 AM
|
SQL Server trigger on specific column updated
Tag : sql , By : Jason Jennings
Date : March 29 2020, 07:55 AM
hope this fix your issue I have a table with the following columns: , thanks to Mr. Bhosale USE [lms_db]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TRIGGER [dbo].[updateLM_TIME]
ON [dbo].[INSTITUTIONS]
AFTER INSERT, UPDATE
AS
IF NOT UPDATE(CLIENT_SYNCED_TIME)
BEGIN
UPDATE dbo.INSTITUTIONS
SET lm_time = CONVERT(DATETIME, CONVERT(VARCHAR(20), GETDATE(), 120))
WHERE ID IN (SELECT DISTINCT ID FROM Inserted)
END
|
How to add a trigger if column has updated with specific string
Tag : mysql , By : Luciano Campos
Date : March 29 2020, 07:55 AM
hop of those help? I want to add a trigger if name has update with "NEW_" string. Below is my current trigger but its working without checking the updated value contain "NEW_" . please advice , Use this: CREATE TRIGGER update_user_deleted_date BEFORE UPDATE ON users
FOR EACH ROW BEGIN
IF (LOCATE('NEW_', NEW.name) != 0) THEN
SET NEW.date_deleted = NOW();
END IF;
END;
|
fire after update trigger if the updated column value is equal to 'APPROVED'
Tag : sql , By : vitorcoliveira
Date : March 29 2020, 07:55 AM
I wish did fix the issue. You can't control whether the trigger will be fired or not, but you can control what will happen inside the trigger. You should be aware that triggers are fired based on statements, not on rows, so be careful not to assume the inserted table will only contain one row. CREATE TRIGGER dbo.tr_Test ON dbo.Test FOR UPDATE
AS
INSERT INTO test_audit (Id, Name, [Status], [time stamp])
SELECT Id, Name, [Status], GETDATE()
FROM Inserted I
WHERE I.[Status] = 'APPROVED'
AND EXISTS
(
SELECT 1
FROM Deleted D
WHERE D.Id = I.Id -- assuming primary key column is called id...
AND D.[Status] <> 'APPROVED'
)
|