unsigned short data type in my Sql server 2008 r2

我是研究僧i 提交于 2019-12-11 03:36:47

问题


I want to store Port numbers in my SQL server database. In general and any port can have values from (0 to 65,535).

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.

But in my case I am suing Sql server 2008 r2, so which data type I can use to represent “unsigned short”?

Regards


回答1:


See the documentation on data types.

You could use a decimal/numeric:

Precision     Storage bytes
1-9           5
10-19         9
20-28         13
29-38         17

but even the smallest precision (1-9) is 5 bytes.

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

... a smallint is too small, so just use integer. It'll save you an extra byte every time compared to decimal/numeric every time.



来源:https://stackoverflow.com/questions/17348848/unsigned-short-data-type-in-my-sql-server-2008-r2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!