Is it ok to use character values for primary keys?

前端 未结 7 1114
悲&欢浪女
悲&欢浪女 2021-01-19 10:54

Is there a performance gain or best practice when it comes to using unique, numeric ID fields in a database table compared to using character-based ones?

For instanc

7条回答
  •  自闭症患者
    2021-01-19 11:06

    Text is fine, for all the reasons you mentioned.

    If the string is only a few characters, then it will be nearly as small an an integer anyway. The biggest potential drawback to using strings is the size: database performance is related to how many disk accesses are needed. Making the index twice as big, for example, could create disk-cache pressure, and increase the number of disk seeks.

提交回复
热议问题