我的 Sql server 2008 r2 中的无符号短数据类型 [英] unsigned short data type in my Sql server 2008 r2
问题描述
我想将端口号存储在我的 SQL 服务器数据库中.一般来说,任何端口的值都可以从(0 到 65,535).
I want to store Port numbers in my SQL server database. In general and any port can have values from (0 to 65,535).
在以下链接上http://msdn.microsoft.com/en-us/library/s3f49ktz%28v=vs.71%29.aspx 提到unsigned short"将适合存储端口号.
And on the following link http://msdn.microsoft.com/en-us/library/s3f49ktz%28v=vs.71%29.aspx it is mentioned that "unsigned short" will be suitable for storing Port number.
但就我而言,我起诉的是 Sql server 2008 r2,那么我可以使用哪种数据类型来表示无符号短"?
But in my case I am suing Sql server 2008 r2, so which data type I can use to represent "unsigned short"?
问候
推荐答案
请参阅 关于数据类型的文档.
您可以使用十进制/数字:
Precision Storage bytes
1-9 5
10-19 9
20-28 13
29-38 17
但即使是最小的精度 (1-9) 也是 5 个字节.
but even the smallest precision (1-9) is 5 bytes.
查看整数族 (并忽略 bigint
因为它太过分了):
Looking at the integer family (and ignoring bigint
because it's overkill):
Data type Range Storage
int -2^31 (-2,147,483,648) to 2^31-1 (2,147,483,647) 4 Bytes
smallint -2^15 (-32,768) to 2^15-1 (32,767) 2 Bytes
tinyint 0 to 255 1 Byte
...smallint
太小了,所以只用 integer
.与每次 decimal
/numeric
相比,它每次都会为您节省一个额外的字节.
... a smallint
is too small, so just use integer
. It'll save you an extra byte every time compared to decimal
/numeric
every time.
这篇关于我的 Sql server 2008 r2 中的无符号短数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!