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

前端 未结 6 808
感情败类
感情败类 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:13

    Having primary key null can be beneficial in some scenarios. In one of my projects I used this feature during synchronisation of databases: one on server and many on different users devices. Considering the fact that not all users have access to the Internet all the time, I decided that only the main database will be able to give ids to my entities. SQLite has its own mechanism for numbering rows. Had I used additional id field I would use more bandwith. Having null as id not only notifies me that an entity has been created on clients device when he hadn't access to the Internet, but also decreases code complexity. The only drawback is that on clients device I can't get an entity by it's id unless it was previously synchronised with main database. However thats not an issue since my user cares for entities for their parameters, not their unique id.

提交回复
热议问题