DB designs that do not impose NOT NULL constraints on flag items such as enable and delete flags are common."According to the specification, ""Please treat 0 and NULL in the same sense,"" but is there any disadvantage of giving NOT NULL constraints (and default values)?
What are the disadvantages of imposing NOT NULL constraints on items that do not need to store NULL, not just flag items?
database database-design
Developers' experience has shown that it is more beneficial to impose NOT NULL constraints on items that do not require NULL.
Your question is similar to SQL Anti-pattern, which is called Fear of the Unknown
.(I don't have any data, so I remember it vaguely.)However, in Fear of the Announ, NULL would have mentioned anti-patterns that put NOT NULL constraints on items that require NULL.
For example, when unentered = unknown
is set in the column male=1
female=2
, an "unknown" is added to the input field one day to make unknown
unentered=null
.
Another anti-pattern is that columns that require NOT NULL constraints are not constrained.
When searching for a record that is not flagged valid, if NULL and '0' are mixed, some anti-patterns cannot get the correct result in ENABLE_FLG NOT in('1')
.
I remember that the conclusion of the above document was to understand the characteristics of NULL and use it appropriately, and to avoid anti-patterns with NOT NULL constraints if necessary.
As for the disadvantages of imposing NOT NULL constraints, some people may argue that the operation such as insert is a little slow.
According to the verification article, Oracle will slow down approximately 0.6 percent if you insert 1 million data.
The speed difference is negligible in real-world operations.
The main reasons for designing flag items not to impose NOT NULL constraints are as follows:
ENABLE_FLG='1'
, so anything else is fine.
In any case, not imposing the necessary constraints is similar to the state in which the intent of the table design is not reflected in the substance of the table, and the composer does not write strong or weak symbols such as Forte Piano on the sheet music.
Wouldn't it be healthier to have an environment in which developers and performers can't do anything unfair due to restrictions than to have an environment in which they interpret freely?
*We can't prevent the tragedy of newcomers and infrastructure teams saying, "I'm not sure, so I removed the restrictions!" but we will not include it in our answers because it's about sharing information and the system.
© 2024 OneMinuteCode. All rights reserved.