logo
down
shadow

sql trigger to update based on specific column is updated and if value is equal to 'x'


sql trigger to update based on specific column is updated and if value is equal to 'x'

Content Index :

sql trigger to update based on specific column is updated and if value is equal to 'x'
Tag : sql-server , By : Angel Paunchev
Date : November 26 2020, 01:01 AM


Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

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


Tag : sql , By : dlouzan
Date : March 29 2020, 07:55 AM
I wish this help you You are using deleted table as source, which contain data BEFORE your update run. Replace it with inserted table which have the new data.
MSDN - Use the inserted and deleted Tables

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'
    )
Related Posts Related QUESTIONS :
  • How to correct an error in SELECT statement
  • All cases when check constraints are executed for each row
  • Exporting database data to csv in classic asp
  • Why does this char value not convert to datetime?
  • How to get file type from binary data in SQL Server File table?
  • Reading derived column expression
  • How do I persist sales price in an orders details table?
  • How to extract data from xml nodes as table from column?
  • Removing Leading and Trailing Zeros along with a Case
  • How to insert new line Char(13) in T-SQL
  • Get first date record from multiple records
  • SQL Server Procedure Returning -1
  • Underscore in Where clause yields unexpected result, why?
  • How to calculate the SID for new logins?
  • Purpose of defining parameters in Access query
  • Windows API call "RegGetValueW" returned error code: 0
  • How to convert CURSOR based query in to SET based
  • Why my main query is running successfully at the same time as subquery returns an error?
  • Rounding up starting 6
  • How to use INSERT INTO OPENROWSET to export to Excel without being an admin on the target server
  • SQL SERVER job is not executing SSIS
  • How to convert Row by row execution in to SET based approach in SQL
  • How to copy databases automatically from one server to another in efficient way (not backup and restore)
  • How to combine rows of similar results into one?
  • Convert HH:MM TT to Time and append onto date
  • Dynamic stored procedure to update a table
  • How do you debug or step through the code in SQL Server Management Studio 18?
  • How to import .bak file into SQL Server?
  • SQL Server Wildcard Length
  • SQL Server : column data extraction
  • The nullability property of arithmetic operators over floating point data type in SQL Server
  • MD5 Hashing in SQL Server
  • How to extract every 7 characters of an nvarchar into another table?
  • ARX Anonymization Tool - supported databases
  • What are good practices for granting database permissions to a web service connection?
  • Go MSSQL Connection
  • SQL Server select query very slow
  • How to delete from multiple tables in one DELETE statement in a .cfc file?
  • Is it possible to get "NT AUTHORITY\NETWORK SERVICE" user independent of language?
  • How to select date and previous date
  • Cleaning dupes and keeping max data
  • Why would adding a simple field to select change the amount of returned rows SQL
  • Read file in SSIS Project into a variable
  • A simple pivot but can't get my head around it - please assist..:-)
  • SQL Server INSERT INTO using transaction
  • How to select from table one with all records from table 2
  • How to migrate collections from TFS 2017 to Azure DevOps Server 2019 (Different DB servers)
  • How to fix error Msg 102, Level 15, State 1, Line 2 Incorrect syntax near ','.?
  • I am getting this error even after declaring scalar variable"'Must declare the scalar variable "@col_shipping_
  • What is the difference between 'CREATE USER [user_name] FOR LOGIN [login_name]' and 'CREATE USER [user_name] FROM LOGIN
  • How to handle a subquery with no results?
  • Access linked to SQL Server shows #Name? in fields after filtering
  • What is different between the two methods of generating cluster primary keys?
  • How can I restore an SQL Server database when starting the Docker container?
  • How to call a SQL Server procedure with both input and output parameters?
  • SQL: Can this be written more efficiently?
  • Why are and are the same in SQL Server
  • date function will return different date if date changes while executing the query?
  • Creating a function for a snap, crackle, pop
  • Difference between SSDT in VS and Integration Services in SQL Server
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com