Default values are not only used for database creation, but also used by the GUI or Indicium to set the default values for the new row.
That's why you can also set them for views, variants etc. Implementing this change is not as simple as changing the code generation, we'd also need to updated the GUI's and Indicium to be able to set expressions as default values.
Sidenote - Be careful using suser_name(), suser_sname(), system_user or other database functions to obtain the user name. These will return the pooling user when you use a Web, Mobile- or Universal GUI or a Windows GUI on Indicium. My advice would be to use dbo.tsf_user() instead.
Big. Fat. Yes. to this one. It's a shame you have to write defaults and such to only fill the current date when adding a row. Being able to set this as default value would be so much easier! AND a great addition to the 'Low - Code' principle.
If you want to use this filling the trace columns automatically when inserting a record in the GUI then it is not going to work since the GUI fills in null values for each field which has not been filled by the user. This means that in your example the insert_user and insert_date_time columns will have null values instead of the username and the current date. The default value will only be set when no value has been given. If you set the columns to mandatory (not null) then the GUI will show an error because it passes a null value since the (data) model does not allow nulls.
This could be fixed when the GUI also allows to pass default as a value when a column has not been filled by the user.
For example:
I created a table called test_tab which has a column insert_date_time. On the database I manually set the default value to getdate() (as in your example).
When I insert a record within my Windows GUI the debugger says it executes the following insert statement:
You have to realize that database defaults don't work for update statements. It only works for insert statements where the field with the default is not in the column list.
With this knowledge, is it still something you really need?
We use 3 different kinds of cookies. You can choose which cookies you want to accept. We need basic cookies to make this site work, therefore these are the minimum you can select. Learn more about our cookies.