Database Design Primay Key, ID vs String

前端 未结 5 1487
执笔经年
执笔经年 2021-02-01 16:11

I am currently planning to develop a music streaming application. And i am wondering what would be better as a primary key in my tables on the server. An ID int or a Unique Stri

5条回答
  •  生来不讨喜
    2021-02-01 16:44

    This is in large part a matter of personal preference.

    My personal opinion and practice is to always use integer keys and to always use surrogate rather than natural keys (so never use anything like social security number or the genre name directly).

    There are cases where an auto number field is not appropriate or does not scale. In these cases it can make sense to use a GUID, which can be a string in databases that do not have a native datatype for it.

提交回复
热议问题