Skip to main content
added 140 characters in body
Source Link
user22815
user22815

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. For example: on insert, field C is set to the sum of fields A and B, instead of some fixed value such as zero. That is "insertion logic."

"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.

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.

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. For example: on insert, field C is set to the sum of fields A and B, instead of some fixed value such as zero. That is "insertion logic."

"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.

Source Link
user22815
user22815

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.