English 中文(简体)
大型表格最佳主要格式
原标题:Best primary key format for large table

I m 开发一个具有某些潜在较大数据表的蚊帐应用。 我愿知道,确定首要钥匙的最佳方式是什么。 我知道以前曾提出过这个问题,但由于情况特殊,我认为这个问题是有效的。

在2008年服务器数据库中使用实体框架4。

考虑到以下因素,界定主要关键的可能性是什么:

  1. There is a real possibility that over time the number of records will exceed the 32 bit boundary, so an auto-increment integer will not be possible.
  2. There is no possibility to define a primary key on a combination of other columns in the table.
  3. For data synchronization reasons, an application-generated id would be preferable over a database-generated id. Also, in EF it would mean an extra roundtrip to the database to retrieve the newly generated id.
  4. For insert performance, a sequential key would be preferable.
  5. I consider the space requirements for a (sequential) guid a downside.
  6. For string id s, case insensitivity would be preferable.

我迄今亲眼看到的是一种习俗算法,它产生一个白天部分和随机部分,变成了六dec代代表。 这使我留下的体力略低于指导。 我仍可以将其改为64,但这将涉及项目6。

感谢您的建议。

最佳回答

您可考虑将贵钥匙储存为BIGINT(8 byte integer)。

BIGINT公司与INT公司完全一样,可以以同样的方式在自动加固的身份栏中使用。

问题回答

这里有两点想法。

  • Consider the binary data type of size 5 or 6 bytes.
  • Do not overlook the benefits of partitioned tables especially for large tables.
  • Keep the remaining columns as small as possible. Sometimes the star schema can help with this.

不幸的是,你不能把双元数据识别栏列。 但您可使用<代码>max(Id)+1插入战略。 我不是这样熟悉的。 NET是实体框架,但应当有办法在同一次访问中检索钥匙。 我过去看到了文件,解释如何绘制实体的地图,以储存程序,并从中提取钥匙,但我没有任何具体内容。

我将在您的案例中使用一个顺序式的《国际统一准则》。

  • it is a surrogate key
  • it is application generated, so no need to retrieve a database generated id after inserts
  • it is sequential and will work well with clustered indexes
  • if you may overflow 32 bit keys you will probably have to use 64 bit keys anyway (besides you manage to create and use 48 bit keys or something like that) - then 128 bit GUIDs only require twice the space
  • string surrogate keys are somewhat unnatural to me and I can see no benifit over GUID keys




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签