按字母顺序在列中存储值?

发布于 2024-10-09 18:10:13 字数 336 浏览 0 评论 0原文

在列中按字母顺序存储内容有什么好处吗?也许可以让查找速度更快?如果是,那么当我向表中添加新的查找值时,是否需要重建查找值的 PK 以适应新文本?说一个这样的表:

City_tbl
city_id:示例:1120
City_name:例如:纽约。

如果我需要将芝加哥添加到其中,我是否将其添加到列表底部,下一个 ID 可能是 2000,还是将其按字母顺序插入到城市后面,这意味着我需要更新所有的 PK Id跟随 ID 1。

我知道的唯一好处是,当我必须手动添加查找值而不查询数据库时,我可以轻松快速检查现有项目的查找值列表。但不确定它是否可以使查找更快,或者如果系统知道文本是按字母顺序排列的。

Is there any benefit to storing content alphabetic in columns? Maybe make lookups faster? If yes then when i add new lookup values to my tables do i need to rebuild the PK for the lookup values to fit in the new text? Say a table like this:

City_tbl
city_id: example: 1120
City_name: example: New York.

If I need to add Chicago to it, do i add it at the bottom of the list with the next ID which may be 2000 or do i inset it after the city in alphabetic order which would mean I need to update the PK Id of all following IDs by 1.

Only benefit I know about is when I have to manually add lookup values without querying the database I can quickly check the lookup value list for exiting items with ease. But not sure if it may make lookups faster or something if the system knows the text is in alphabetical order.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酒儿 2024-10-16 18:10:14

不,我认为它没有任何价值。最好使用适当的主键并向列添加索引。花费数年时间编写关系数据库的人比您更了解如何优化访问。

我会让 PK 列自动递增,将更新留给数据库。我会在城市名称列中添加一个索引,以便您可以尽快按名称搜索。

您假设您了解有关数据库物理存储的一些知识。最好的情况下,你的努力不会产生任何效果;最坏的情况是,您会搞砸正确索引的 B 树已经为您提供的快速访问。

No, I see no value in it. Better to use a proper primary key and add an index to the column. The people who have spent years writing relational databases know how to optimize access far better than you do.

I'd make the PK column auto increment, leaving the updating to the database. I'd add an index to the city name column so you can search by name as quickly as possible.

You're presuming that you understand something about the physical storage of the database. At best, your efforts will have no effect; at worst, you'll screw up the fast access that a properly indexed b-tree will already give you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文