Is it frowned upon to have check constraints only applicable to a subset of rows?
0
votes
0
answers
75
views
At my place of work we are running into an issue, we have many parameters stored in a table like so.
| ModelParameterValueID | ModelParameterID | ModelID | CurrentValue | Updated Date |
| --- | --- | --- | --- | --- |
| 187883 | 81 | 10849 | TEMPSTR | 26-Jul-24 |
ModelParameterID = 81
corresponds to a string parameter in our database. Our technicians have some models that need the CurrentValue
nulled, but only for that modelParameterID
. We have a CHECK
in place that makes sure CurrentValue
is not Null
, so I surmised to myself that if we could have a conditional CHECK
that allowed CurrentValue
to be Null
only if ModelParameterID = 81
then this issues would not be there. So I contacted our database administrator and asked him if a change of this kind would be possible. He said
> It is not good practice to have a constraint defined like that based on a particular value in another column.
I asked him to explain but he would not. Could someone explain as to why something like this is frowned upon? And if it indeed is not good practice, then what would an alternative be?
Asked by mhabes
(1 rep)
Sep 26, 2024, 01:41 PM
Last activity: Sep 27, 2024, 08:06 AM
Last activity: Sep 27, 2024, 08:06 AM