Subject Offtopic: Trigger before Insert: Firebird vs. MS SQL
Author Nikolaus Kern

Hello all,

 

I was looking into a very simple question on MS SQL (from a Firebird users point of view): Before INSERT I need to modify the incoming data:

 

Example: INSERT INTO CUSTOMERS (NAME, AGE) value ('Test', 50);

The trigger should simply decrease the age by 1 year.

 

In Firebird it would look like this:

CREATE TABLE CUSTOMER (

  "NAME" VARCHAR(20),

  AGE SMALLINT);

 

 

SET TERM ^ ;

 

CREATE TRIGGER CUSTOMER_BI FOR CUSTOMER

ACTIVE BEFORE

  INSERT

POSITION 0

AS

BEGIN

  /* Trigger body */

   NEW.AGE = new.AGE-1;

END^

 

SET TERM ; ^

 

Is it possible that this works totally different in MS SQL? I could only find triggers that include a full update with where clause to the the current record. Or the INSTEAD OF trigger.

 

https://stackoverflow.com/questions/3580123/how-can-i-edit-values-of-an-insert-in-a-trigger-on-sql-server

 

If somebody has knowledge about this subject a few lines would be very welcome!

 

Thanks

 

Niko