字符串与数字类型 [英] String vs Numeric Type

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

问题描述

如果我决定将主键设为一串数字

vs实际数字会不会有意义?在

效率方面,它会对DB2产生什么影响吗?为什么你会为一个字符串选择数字?

不需要是数字格式?


谢谢

-

回复newsgroupsurferATyahooDOTcom

would it matter if I decided to make a primary key a string of numbers
vs actual numbers ? would it make any difference to DB2 in terms of
efficiency ? why would you choose numeric over a string for a key that
does not need to be in numeric format ?

thanks
--
reply to newsgroupsurferATyahooDOTcom

推荐答案

Victor Mehta写道:
Victor Mehta wrote:
是否重要我决定将一个主键与一些数字相对于实际数字?它在效率方面对DB2有什么影响吗?你为什么要在字符串上选择数字来表示
不需要数字格式的键?
would it matter if I decided to make a primary key a string of numbers
vs actual numbers ? would it make any difference to DB2 in terms of
efficiency ? why would you choose numeric over a string for a key that
does not need to be in numeric format ?




可能是物理数据库中最重要的区别级别是

INTEGER需要4个字节的存储空间,而你需要

CHAR(10)来存储相同的值范围。


但是,这绝不应该在物理数据库级别决定。

您的数据模型将(应该)始终确定适当的域名

您的属性。



Probably the most significant difference at a physical database level is
the fact that INTEGERs require 4 bytes of storage, while you would need
CHAR(10) to store the same range of values.

However, this should never be decided at a physical database level.
Your data model will (should) always determine the proper domain for
your attributes.


Ian写道:
Victor Mehta写道:
Victor Mehta wrote:
如果我决定是否重要使主键成为一串数字
vs实际数字?它在效率方面对DB2有什么影响吗?为什么你会为字符串选择数字而不需要数字格式?
would it matter if I decided to make a primary key a string of numbers
vs actual numbers ? would it make any difference to DB2 in terms of
efficiency ? why would you choose numeric over a string for a key that
does not need to be in numeric format ?



物理数据库级别上最重要的区别可能是 CHAR(10)来存储相同范围的值。

然而,这绝不应该在物理上决定数据库级别。
您的数据模型将(应该)始终确定您的属性的正确域。


Probably the most significant difference at a physical database level is
the fact that INTEGERs require 4 bytes of storage, while you would need
CHAR(10) to store the same range of values.

However, this should never be decided at a physical database level.
Your data model will (should) always determine the proper domain for
your attributes.



确实!我刚刚与一位客户对抗,其中设备ID是一个编码的bb。 比特范围是指比特范围。实现为INTEGER。

接下来我听到的是为什么DB2不支持UNSIGNED INTEGER因为

我们松开了0x8000000位。

在经过一些患者解释并指向

a混合环境中的小端和大端后,他们现在正朝着CHAR(4)for BIT DATA(又名

BINARY)的方向前进。

数据类型没有事后的想法....


干杯

Serge

-

Serge Rielau

DB2 SQL编译器开发

IBM多伦多实验室


Indeed! I''ve just been butting heads with a customer where a "device ID"
which is an "encoding" of "bit ranges" was implemented as INTEGER.
Next thing I hear is "Why doesn''t DB2 support UNSIGNED INTEGER because
we loose the 0x8000000 bit."
After some patient explanation and pointing to little and big endian in
a mixed environment they are inching towards CHAR(4) FOR BIT DATA (aka
BINARY) now.
Data types are no afterthought....

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab


最终,所有数据都存储为位,因此INDEXed的数据类型应该是无关紧要的。就个人而言,我尝试使用INTEGER作为我的PRIMARY KEYs,

,因为我喜欢将TABLE称为对象,而个人

记录为这些对象的实例。在大多数每个

表格中都有一个名为Id的表。让它永远是一个INTEGER非常方便

和一致。另外,如果另一个TABLE是参考这个TABLE,则不需要一个

长的字符串,只需一个(相对)小的INTEGER。


还有其他我喜欢它的原因。我发现当文本用于

标识符时,文本可能会随着时间而改变。一个非描述性的INTEGER

不应该是一个很好的主要关键。然后我将改为

字符字段UNIQUE。


所以,我只是觉得使用INTEGER更合适。


也可以使用字符串。


B.

Ultimately, all data is stored as bits, so the data type INDEXed should
be irrelevant. Personally, i try to use INTEGER as my PRIMARY KEYs,
because i like to refer to TABLEs as objects, and the individual
records as instances of those objects. Having a COLUMN in most every
TABLE called "Id" and having it always be an INTEGER is very convenient
and consistant. Plus, if another TABLE is to REFERENCE this TABLE, a
long character string is not needed, just a (relatively) small INTEGER.

There are other reasons i like it. I find that when text is used for an
identifier, the text may change over time. A non-descript INTEGER
shouldn''t and therefore makes an excellent PRIMARY KEY. I''ll then make
the character field UNIQUE instead.

So, i simply find the use of an INTEGER to be better fitted.

A string can be used just as well.

B.


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

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