Skip to main content
Answer

BEFORE trigger

  • November 23, 2022
  • 2 replies
  • 79 views

Freddy
Forum|alt.badge.img+16
  • Thinkwise Local Partner Brasil

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?

Best answer by Mark Jongeling

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?

This topic has been closed for replies.

2 replies

Mark Jongeling
Administrator
Forum|alt.badge.img+23
  • Administrator
  • Answer
  • November 23, 2022

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?


Freddy
Forum|alt.badge.img+16
  • Author
  • Thinkwise Local Partner Brasil
  • November 23, 2022

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 :)