对于大表最佳主键格式 [英] Best primary key format for large table

查看:162
本文介绍了对于大表最佳主键格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个具有一些潜在的大型数据表的asp.net应用程序。我想知道什么是定义主键的最佳方式。我知道这已经问过,但由于这是一个具体的情况,我认为这个问题是有效的。

I'm developing an asp.net application that has some potentially large data tables. I would like to know what would be the best way to define a primary key. I know this has been asked before, but since this is for a specific situation, I think the question is valid.

我是一个SQL Server上使用实体框架4 2008数据库。

I'm using Entity Framework 4 on a SQL server 2008 database.

什么是定义主键,考虑到以下的可能性:

What are the possibilities for defining a primary key, considering the following:


  1. 有一个现实的可能性随着时间的记录数将超过32位边界,因此自动递增整数将是不可能的。

  2. 没有可能性来定义在其它列在表中的组合的主键。

  3. 有关数据同步的原因,应用程序生成的ID是在一个数据库生成的ID preferable。此外,在EF这将意味着一个额外的往返到数据库检索新生成的ID。

  4. 对于插入性能,顺序键是preferable。

  5. 我考虑了(顺序)的空间要求GUID的缺点。

  6. 对于字符串编号的,不区分大小写将是preferable。

我想出了自己迄今生成日期时间部分和随机部分的自定义算法,转换为十六进制字符串重新presentation。这给我留下了比GUID的略短字符串。我仍然可以将其转换为Base64,但是这将不利于项目NR 6。

What I've come up with myself so far is a custom algorithm which generates a datetime part and a random part, converted to a hexadecimal string representation. This leaves me with a slightly shorter string than a guid. I could still convert it to base64, but that would go against item nr 6.

感谢您的建议。

推荐答案

您可以考虑将你的密钥作为的 BIGINT (8字节整数)。

You could consider storing your key as a BIGINT (8 byte integer).

BIGINT的作品酷似INT,并且可以在一个自动递增标识列以同样的方式被使用。

BIGINT works exactly like INT, and can be used in an auto-incrementing identity column in the same way.

这篇关于对于大表最佳主键格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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