Skip to main content
1 of 2
user avatar
user avatar

If the default is just that, a default value, that is not "business logic." If you insert a record and set an integer to zero, is that logic? Most modern languages (e.g. pretty much anything C-based) would default that to zero anyway. Does it really matter if you default it to one instead?

The way I see it, "insertion logic" goes in an "after insert" trigger. Code executes, it calculates a value, and sets it on the new record.

"Every new record gets a value of 'baz' in the 'foo' field if not already specified" is not really logic in anything but the most trivial sense of the word, certainly not in a complex program.

What uses of the default clause when defining a column are not considered having business logic in the database?

Since you specifically mention "default clause" which would mean "not a trigger," I say all uses of the default clause do not add logic to the database.

As an aside, most databases treat default values as default constraints. In other words, "null is outside of the acceptable values for this field so set it to something within the set of acceptable values instead." If you look at it that way, a default value is almost the same as specifying a range of values for a field. Set it outside that range (null), and you get a default value instead.

user22815