问题
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