NULL permitted in Primary Key - why and in which DBMS?

前端 未结 6 807
感情败类
感情败类 2020-11-29 07:33

Further to my question "Why to use ´not null primary key´ in TSQL?"...

As I understood from other discussions, some RDBMS (for example SQLite, MySQL

6条回答
  •  伪装坚强ぢ
    2020-11-29 08:06

    Well, it could allow you to implement the Null Object Pattern natively within the database. So if you were using something similar in code, which interacted very closely with the DB, you could just look up the object corresponding to the key without having to special-case a null check.

    Now whether this is worthwhile functionality I'm not sure, but it's really a question of whether the pros of disallowing null pkeys in absolutely all cases outweigh the cons of obstructing someone who (for better or worse) actually wants to use null keys. This would only be worth it if you could demonstrate some non-trivial improvement (such as faster key lookup) from being able to guarantee that keys are non-null. Some DB engines would show this, others might not. And if there aren't any real pros from forcing this, why artificially restrict your clients?

提交回复
热议问题