主键列的数字或字符 [英] Number or char for primary key column

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

问题描述

我正在建立一个非常重要的国家机构的数据库。到目前为止,对于主键列我有时使用数字,特别是int32或int64,有时我使用了char但仍然只存储了数字字符。由于这是一项非常关键的任务,我必须使其兼具性能和舒适性。现在我想知道,如果对于PK列使用数字或字符有什么不同,考虑到char列中的值仍然是数字字符。

I'm building a database of a very important state institution. So far, for Primary Key columns I've sometimes used numbers, particularly int32 or int64, and sometimes I've used char but still I stored only numeric characters. Since this a very crucial task I have to make it both performance and comfort-wise efficient. Now I want to know,if it makes any difference to use number or char for a PK column considering the values in the char column will still be numeric characters.

PSYou如果我仍然存储数字字符,可能想知道使用char有什么意义。原因是因为PK栏由多个部分组成,如国家3个字符,省3个字符,城市3个字符和一个人6个字符。除此之外,我可以在这些列上进行字符串操作,而不必担心显式转换。(我知道Oracle中存在隐式转换但不鼓励依赖它。)

P.S.You might wonder what the point is in using char if I anyway store numeric characters. The reason is becuase the PK column is composed of many parts, like 3 characters for country, 3 characters for province,3 characters for city and 6 characters for a person. And besides that I can make string operations on those columns without worrying about explicit conversion.(I know there's implicit conversion in Oracle but it's discouraged to rely on it.)

推荐答案

也不是这样的。
您的主键应该是代理。 Int或big int,Guid如果缩放将是一个问题。
然后你应该把国家,省,城市和人作为一个独特的复合键。 智能数字很少是一个好主意。

Neither as such. Your primary key should be a surrogate. Int or big int, Guid if scaling is going to be an issue. Then you should have country, province, city and person as a unique compound key. The 'intelligent' number thingy is rarely a good idea.

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

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