SQL Server 2019 trigger does not execute

moondaddy 1 Reputation point
2020-08-19T22:07:59.907+00:00

I just moved a database from sql server 2014 to 2019 and now an update trigger does not execute when it should. Here's the first part of the trigger:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TRIGGER [dbo].[UTrig_Customer]
ON [dbo].[tbCustomer]
AFTER INSERT
AS
DECLARE
@Cust_Id uniqueidentifier,
@auditAction_Id uniqueidentifier

BEGIN  
SET NOCOUNT ON;  
  
Bla bla bla...  

and the trigger is enabled.

This trigger should insert a row into an audit table, which does not happen. also, when I execute an update statement from the SSDT debugger it does not step into the trigger:

		UPDATE	tbCustomer  
		SET  
		Cust_Name = @Cust_Name,  
		Cust_Code = @Cust_Code,  
		Cust_CustTp_Id = @Cust_CustTp_Id,  
		Cust_Discount = @Cust_Discount,  
		Cust_St_Id = @Cust_St_Id,  
		Cust_Cnt_Id = @Cust_Cnt_Id,  
		Id_Rank = @Id_Rank,  
		Cust_Notes = @Cust_Notes,  
		Cust_IsActiveRow = @Cust_IsActiveRow,  
		Cust_UserId = @Cust_UserId,  
		Cust_LastModifiedDate = GETDATE(),  
		Cust_auditAction_Id = @auditAction_Id  
		WHERE	(Cust_Id=@Cust_Id)  

any idea why this does not work?

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,325 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Cris Zhan-MSFT 6,611 Reputation points
    2020-08-20T03:41:11.91+00:00

    Hi,

    If the trigger in this database worked normally before, but it does not work after upgrading this database, so this may be related to the database upgrade.
    Have you changed the compatibility level of the database, set it to SQL Server 2019 (150).

    ===============================================
    If the response helped, do "Accept Answer" and upvote it.

    0 comments No comments

  2. tibor_karaszi@hotmail.com 4,306 Reputation points
    2020-08-20T05:28:25.983+00:00

    The trigger is defined to fire on insert, but you execute an update.

    0 comments No comments