Skip to main content
Solved

Call default on editing


Forum|alt.badge.img+15

I'm trying to convert some trigger logic to default logic, because I would like to use the 'system versioned tables'. Having triggers causes a lot of records in the history table, which isn't necessary.

I'm currently using a trigger to update the 'update_user' and 'update_date_time', and also an update_counter for preventing concurrent editing. 

I've tried to set up a default which sets the update_user and update_date_time. Problem is that it's only fired when a column has default logic enabled and the value is changed. What I want is that the default is also triggered when the user starts editing. Or maybe after he's done editing. Then I would like to update the update user / datetime. When inserting a record this happens (e.g. @cursor_from_col_id is null), but when editing it isn't.

A work around is passing all table columns to the default, but I don't want this because it's unneccesary and a performance killer.

Any suggestions on this case, preventing unneccesary records in the history table?

Best answer by Erwin Ekkel

Indeed the default is only triggered when modifying a column that is active in the default. You could create a view instead of the actual table. And have an instead of trigger on the view to do the update including the date/user column on the table.

Using the default with deactivated columns is, like you stated, not an option to set the date/user column.

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

8 replies

Forum|alt.badge.img+17
  • Moderator
  • 761 replies
  • June 10, 2021

Why would you want to modify the 'update_user' and 'update_date_time when nothing was changed? You could just fill these 2 columns when another column is modified triggering the default. 
 

select @update_user = dbo.tsf_user()     , @update_date_time = getdate()

Forum|alt.badge.img+15
  • Author
  • Superhero
  • 196 replies
  • June 10, 2021

The default isn't triggered when the checkbox ‘default input’ and/or ‘default output’ isn't enabled of a column:

In the example above it's only triggered when you leave the (editable) ‘name’ field. It's not triggered when for example leaving the field ‘phone_number’, although it is changed.

So it is only possible when all checkboxes are enabled, but I think that is unneccesary and is performance wise not desireable.

I was hoping the default was triggered when going into edit mode, just like it does when adding a new rule, but unfortunately it doesn't.

 


Forum|alt.badge.img+17
  • Moderator
  • 761 replies
  • June 10, 2021

What GUI(s) are you using? Did you try it with the default/input output activated and did it have a huge performance difference? 

 


Forum|alt.badge.img+15
  • Author
  • Superhero
  • 196 replies
  • June 10, 2021

We're using the WebGUI as GUI, but for development purposes (debugging) we also use the Windows GUI. In an early stage of our product development we've encountered some serious performance degradation by passing to much parameters in default, layout and context logic. Our strategy is to pass only the parameters that are needed.


Forum|alt.badge.img+17
  • Moderator
  • 761 replies
  • Answer
  • June 10, 2021

Indeed the default is only triggered when modifying a column that is active in the default. You could create a view instead of the actual table. And have an instead of trigger on the view to do the update including the date/user column on the table.

Using the default with deactivated columns is, like you stated, not an option to set the date/user column.


Arie V
Community Manager
Forum|alt.badge.img+12
  • Community Manager
  • 979 replies
  • June 12, 2021

Hi @René W I’m curious to hear which solutions you’ll end up with! We have the same situation with system-versioned tables and multiple triggers cluttering the system-versioned data, of which also the update_user/update_date_time and update_counter. Only difference is that we’re using Universal GUI. 

Two things I could mention from our situation:

  • We discussed using Defaults too, but as we have these fields for logging purposes it is important to us to have update_date_time equal the DB transaction time. Since Defaults are set upon entering edit mode or upon editing another column, we didn’t see Defaults as a fitting option. Saving/committing of the record could be done quite a bit later than the defaulted date_time.
  • We have it on the backlog to try and combine the 2 update triggers, this saves a row in the system-versioned table for every commit.

Are there other alternatives to consider?


Forum|alt.badge.img+15
  • Author
  • Superhero
  • 196 replies
  • October 20, 2021

The topic is marked as answered, but in my opinion it isn't. There is unfortunately no answer for my question I think.


Arie V
Community Manager
Forum|alt.badge.img+12
  • Community Manager
  • 979 replies
  • October 20, 2021

@René W Two updates from our side on this topic:

  1. We indeed merged the update_user/update_date_time and update_counter triggers into a single one, that saves a record for each change.
  2. We also added a pre-filter on the view that by default hides the trigger-invoked changes, basically by hiding records for which tsf_valid_from = tsf_valid_to. Although this technically doesn't reduce the nr of records in the history table, it does reduce the clutter in the view.

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