Skip to main content
Solved

BEFORE trigger

  • November 23, 2022
  • 2 replies
  • 73 views

Freddy
Forum|alt.badge.img+16
  • Thinkwise Local Partner Brasil
  • 528 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?

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?

View original
Did this topic help you find an answer to your question?
This topic has been closed for comments

2 replies

Mark Jongeling
Administrator
Forum|alt.badge.img+23
  • Administrator
  • 3936 replies
  • 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
  • 528 replies
  • November 23, 2022
Mark Jongeling wrote:

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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings