将整数作为字符串存储在数据库中的缺点
我有需要存储的产品的ID值.现在它们都是整数,但是我不确定将来的数据提供者是否会在混合中引入字母或符号,因此我正在讨论是否现在将其存储为整数或字符串.
I have id values for products that I need store. Right now they are all integers, but I'm not sure if the data provider in the future will introduce letters or symbols into that mix, so I'm debating whether to store it now as integer or string.
将值另存为字符串是否有性能或其他缺点?
Are there performance or other disadvantages to saving the values as strings?
除非您真的需要整数的功能(即具有算术能力),否则最好将产品ID存储为字符串.您将不需要做任何事,例如将两个产品ID加在一起,或计算一组产品ID的平均值,因此不需要实际的数字类型.
Unless you really need the features of an integer (that is, the ability to do arithmetic), then it is probably better for you to store the product IDs as strings. You will never need to do anything like add two product IDs together, or compute the average of a group of product IDs, so there is no need for an actual numeric type.
将产品ID存储为字符串不太可能导致可测量的性能差异.尽管存储大小会略有增加,但是产品ID字符串的大小可能会比数据库其余行中的数据小得多.
It is unlikely that storing product IDs as strings will cause a measurable difference in performance. While there will be a slight increase in storage size, the size of a product ID string is likely to be much smaller than the data in the rest of your database row anyway.
如果数据提供者决定开始使用字母或符号字符,那么今天将产品ID存储为字符串将为将来减轻很多麻烦.没有真正的缺点.
Storing product IDs as strings today will save you much pain in the future if the data provider decides to start using alphabetic or symbol characters. There is no real downside.