MS SQL Server: Setting Default Values for Fields
Let's say you want certain fields to have their values set automatically when not explicitly passed. You can do this in the following ways:
- MS SQL Server defaults: configure default values, using
fixed values or simple SQL functions, for columns in the table definition. E.g. an auto-incrementing
id
, acreated_at
timestamp, etc. - Role based column presets: set up presets, using
session variables or fixed values, that are applied when a row is created/updated with a particular
user role. E.g. set a
user_id
field automatically from a session variable/authorization header.