Solved

BEFORE trigger

  • 23 November 2022
  • 2 replies
  • 50 views

Userlevel 5
Badge +16
  • Thinkwise Local Partner Brasil
  • 384 replies

How do I create a BEFORE trigger on a table still have the AFTER trigger working? 

I just noticed there is only the INSTEAD OF and AFTER trigger, can we create a BEFORE trigger with the SF?

icon

Best answer by Mark Jongeling 23 November 2022, 20:42

View original

This topic has been closed for comments

2 replies

Userlevel 5
Badge +16

Hi Freddy,

To my knowledge, SQL Server does not have Before triggers. You can write an Instead-of-trigger that first does the queries that you would like to put in the before trigger, thereafter do the actual operation, f.e. Inserting the data, and lastly run the queries that are now part of the After trigger.

Some more information I found here: https://databasefaqs.com/sql-server-trigger-before-insert/

Does that help?

 

Yes, I am mistaken. On DB2 it does have a before, on SQL Server it's the instead of trigger that completely replaces the (after) trigger on SQL server. 

I am up to date again :)

Userlevel 7
Badge +23

Hi Freddy,

To my knowledge, SQL Server does not have Before triggers. You can write an Instead-of-trigger that first does the queries that you would like to put in the before trigger, thereafter do the actual operation, f.e. Inserting the data, and lastly run the queries that are now part of the After trigger.

Some more information I found here: https://databasefaqs.com/sql-server-trigger-before-insert/

Does that help?