ID数据类型问题 [英] ID data type question

查看:98
本文介绍了ID数据类型问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要决定对我的实体键字段(在我的SQL Server数据库和我的类中)使用int或nid;或Guid 数据类型。 Guid可能有一些优势,但由于我的客户是移动网络应用程序,我害怕每次
需要通过空中传输的Guid大小。 int的大小要小得多。因此我的问题是:如果这个(= Guid的大小)是(性能)瓶颈,我是对的吗?

I need to decide on using an int or Guid datatype for my Entities key fields (in both my SQL Server db and my Classes). Guid's have probably some advantages but since my client(s) are mobile webapps I'm afraid of the Guid-size that everytime needs to go over the air. The size of an int is much smaller. Therefore my question: am I right if this (=size of Guid) will be a (performance)bottleneck or not?

谢谢。

Guy

Thanks.
Guy

推荐答案

这实际上取决于您在移动设备上来回传递的行数。  如果它只是少数行,那么我仍然会使用GUID。  网络速度现在正处于这样的决策可以落在更好的整体设计方面,而不是速度/效率设计方面。  尽管如此,这并不是让代码变得草率的绿灯,但它确实意味着更容易做出这种权衡。  即使GUID比int主键大4倍,GUID也可以在任何地方生成
,而无需往数据库进行往返以创建新密钥。  仅此一项意味着如果在客户端上创建新行,则可以避免来自数据库的请求和响应。  所以,可能会有权衡,但它们并不像他们最初看起来那么糟糕。  我建议GUID。

It really depends on the amount of rows that you are passing back and forth to the mobile device.  If it's just a handful of rows, then I would still use GUID.  Network speed is now at the point where this kind of decision can fall on the side of better overall design vs designing for speed/efficiency.  Though, this is not a green light to get sloppy with code, but it does mean that it's easier to make this trade-off.  Even though GUID is 4x larger than an int primary key, GUIDs can be generated anywhere, without having to make a roundtrip to the database to create a new key.  This alone means that you avoid a request and response from the database if you create a new row on the client.  So, there may be tradeoffs, but they aren't really as bad as they first seem.  I suggest GUID.


这篇关于ID数据类型问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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