Is it ok to use character values for primary keys?

前端 未结 7 1053
悲&欢浪女
悲&欢浪女 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:25

    The standard answer is to use numbers because they are faster to index; no need to compute a hash or whatever.

    If you use a meaningful value as a primary key you'll have to update it all through you're database if the team name changes.

    To satisfy the above, but still make the database directly readable,

    • use a number field as the primary key

    • immediately create a view Athlete_And_Team that joins the Athlete and Team tables

    Then you can use the view when you're going through the data by hand.

    0 讨论(0)
提交回复
热议问题