The Cost of GUIDs as Primary Keys

简介:
< DOCTYPE html PUBLIC -WCDTD XHTML TransitionalEN httpwwwworgTRxhtmlDTDxhtml-transitionaldtd>

form:http://www.informit.com/articles/article.aspx?p=25862&redir=1
In this article, Jimmy Nilsson presents the pros and cons of using globally unique identifiers (GUIDs) as the datatype for primary keys in SQL Server 2000. In doing so, he shows you test results that hint of performance characteristics and introduces you to a special type of GUID that he invented, called COMBs, that solves what otherwise might give you a big throughput problem.

Natural or Surrogate Keys

When you do the physical design of a relational database, it's very important to decide upon which style to use for the primary keys. Some people prefer to use natural keys—that is, keys that are found in the domain that the database models. Others prefer to use surrogate keys, which are constructed keys with no other purpose than to be just keys (and which are not found in the domain). An example of a natural key is a Social Security number. A value incrementing by 1 for each row is a typical example of a surrogate key.

Using natural keys is the traditional approach, in line with Codd's original relational model. When you use them, you have only natural data that means something to users. This is good if users will ask ad hoc queries directly to the database in raw SQL. You can also often reduce the numbers of joins when using natural keys because you don't have to go to a lookup table to convert an ID to a description. One more advantage is that you get the minimum number of constraints because you don't have to protect the uniqueness of the natural keys separately. You already did this when you used them as primary keys.

Surrogate keys can be seen as a newer approach. This approach does not conflict with the relational model, but, in a way, it is a step closer to a more object-based approach in which each object has an ID and the structure of all IDs is of the same type. When you use surrogate keys, you often get smaller foreign keys, which reduces the size of the database. There is no risk of users changing the values of the primary keys, and the programming can be more consistent because all keys are of the same format.

NOTE

With cascading updates/deletes in SQL Server 2000, the problem of users changing the values of primary keys is not so great anymore because you don't have to program the UPDATE of dependent rows manually.

That was a brief description of the different kinds of keys. Now let's assume that we choose to use surrogate keys when we design a new database.



本文转自 netcorner 博客园博客,原文链接: http://www.cnblogs.com/netcorner/archive/2008/08/08/2912112.html  ,如需转载请自行联系原作者


相关文章
|
数据采集 搜索推荐 数据管理
基于Python爬虫的垂直搜索引擎设计与实现
基于Python爬虫的垂直搜索引擎设计与实现
388 1
|
9月前
|
人工智能 Cloud Native Serverless
2种方式1键部署,快速体验QWQ-32B 模型
QwQ-32B 推理模型现已正式发布并开源,其卓越性能在多项基准测试中表现突出,与全球领先模型比肩。阿里云函数计算 FC 提供算力支持,Serverless+AI 云原生应用开发平台 CAP 提供两种部署方式:模型服务和应用模板,帮助用户快速部署 QwQ-32B 系列模型。用户可通过一键部署体验对话功能或以 API 形式接入 AI 应用。文档详细介绍了前置准备、部署步骤及验证方法,并提供删除项目指南以降低费用。来源:阿里云开发者公众号;作者:肯梦、折原。
2种方式1键部署,快速体验QWQ-32B 模型
|
存储 缓存 搜索推荐
优化PHP数组性能
优化PHP数组性能
187 8
|
9月前
|
人工智能 Java API
Java 也能快速搭建 AI 应用?一文带你玩转 Spring AI 可观测性
Java 也能快速搭建 AI 应用?一文带你玩转 Spring AI 可观测性
496 4
|
安全 Python
使用Python实现简单的Web服务器
使用Python实现简单的Web服务器
445 6
|
数据采集 Web App开发 JavaScript
快速参考:用C# Selenium实现浏览器窗口缩放的步骤
在C#结合Selenium的网络爬虫应用中,掌握浏览器窗口缩放、代理IP、cookie与user-agent设置至关重要。本文详述了如何配置代理(如亿牛云加强版),自定义用户代理,启动ChromeDriver,并访问目标网站如抖音。通过执行JavaScript代码实现页面缩放至75%,并添加cookie增强匿名性。此策略有效规避反爬机制,提升数据抓取的准确度与范围。代码示例展示了整个流程,确保爬虫操作的灵活性与高效性。
346 3
|
人工智能 开发者 黑灰产治理
“用 AI 修复亚运珍贵史料”活动介绍及活动规则【更新获奖名单】
2023年,正值亚运110周年,也是第19届杭州亚运会即将举办之际,阿里云与亚奥理事会合作,发起“历久弥新——用 AI 修复亚运会珍贵史料”活动,开发者使用阿里云的 AI 技术对亚运会历史老照片进行修复,重燃亚运经典,为亚运助威,并有机会入选“亚运史上第一个 AI 修复特展“。
27960 5
“用 AI 修复亚运珍贵史料”活动介绍及活动规则【更新获奖名单】
|
边缘计算 缓存 网络协议
【计算机网络】—什么是蜂窝移动网络?
【计算机网络】—什么是蜂窝移动网络?
|
Ubuntu 应用服务中间件 nginx
Ubuntu系统重启自动启动Docker容器
Ubuntu系统重启自动启动Docker容器
1546 1
EMQ
|
机器学习/深度学习 边缘计算 JSON
车联网 CAN Bus 协议介绍与数据实时流处理
CAN Bus 是一种串行通信协议,能够让设备之间可靠而高效地传输数据。本篇博客将探讨使用 CAN Bus 中遇到的挑战,以及如何用 eKuiper 和 MQTT 解决这些问题。
EMQ
707 0
车联网 CAN Bus 协议介绍与数据实时流处理

热门文章

最新文章