0

I am using Sybase ASE 15.7. I wish to create trigger before insert such that before inserting, I want to modify some fields in the inserted row.

Please help Thanks!

joe
  • 77
  • 2
  • 9

1 Answers1

0

From a trigger perspective you have a couple options:

  • for insert trigger; must be defined against the base table; this trigger will fire after the data has been inserted to the table; the trigger would be coded to perform updates against the base table of the newly inserted row
  • instead of trigger; must be defined against a view (the view would be defined against the base table); you would perform your insert against the view which would cause the instead of trigger to fire; the trigger would be coded to copy/manipulate the data from the inserted pseudo-table and write the final data set into the base table

See create trigger for more details.


Another option would be to write a stored procedure that does all of the pre-insert changes; instead of inserting directly to the base table you would call the stored proc (passing in all of the column values as input parameters). [granted, less than ideal]

'course one other option would be to have the application perform the pre-insert checks and edits before inserting the final data set to the base table.

markp-fuso
  • 28,790
  • 4
  • 16
  • 36
  • So there is no way we can do before insert directly in trigger itself like we do in Oracle? – joe Jan 08 '21 at 07:29
  • I cannot do in application. Insert comes from varied places – joe Jan 08 '21 at 09:35
  • if you cannot modify the `varied places` to perform inserts against a view (with a `instead of` trigger on the view) then, no, you won't be able to pre-modify the data before it's inserted into the table – markp-fuso Jan 09 '21 at 01:24