作为SQL数据库中的主键的字符串 [英] Strings as Primary Keys in SQL Database

查看:136
本文介绍了作为SQL数据库中的主键的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不太熟悉数据库和它们如何工作的理论。从性能的角度(插入/更新/查询)使用主键的字符串比整数慢吗?

I am not very familiar with databases and the theories behind how they work. Is it any slower from a performance standpoint (inserting/updating/querying) to use Strings for Primary Keys than integers?

推荐答案

技术上是肯定的,但如果字符串是主键,那么你应该使用它。这一切都取决于你为它的表的大小和字符串的长度将成为主键(更长的字符串==难以比较)。我不一定使用一个字符串的表有数百万行,但你通过使用较小的表上的字符串将获得的性能减慢的量将是微不足道的,你可以拥有一个整数,不是指与数据相关的任何东西。

Technically yes, but if a string makes sense to be the primary key then you should probably use it. This all depends on the size of the table you're making it for and the length of the string that is going to be the primary key (longer strings == harder to compare). I wouldn't necessarily use a string for a table that has millions of rows, but the amount of performance slowdown you'll get by using a string on smaller tables will be minuscule to the headaches that you can have by having an integer that doesn't mean anything in relation to the data.

这篇关于作为SQL数据库中的主键的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆