2013-06-27 51 views

回答

2

documentation on data types

可以使用decimal/numeric

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

,但即使是最小的精度(1-9)爲5個字節。在integer family

尋找(並忽略bigint,因爲它是矯枉過正):

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相比,它會爲您節省一個額外的字節。

+0

感謝您的答覆,但爲什麼int總是會佔用4個字節,無論其長度。我的意思是如果我有象(2,000,000)這樣的整數和像(420)這樣的整數,這兩個整數是否會佔據相同的存儲空間? –

+0

@johnG - 它們都佔用相同數量的存儲空間,因爲這是SQL Server將數據類型存儲起來的方式。 – LittleBobbyTables