| 類別 | 資料類型 |
|---|---|
| 精確數值 | bigint, int, smallint, tinyint, bit, decimal/numeric, money/smallmoney |
| 近似數值 | float, real |
| 日期時間 | datetime, smalldatetime |
| 字元字串 | char, varchar, text |
| Unicode 字串 | nchar, nvarchar, ntext |
| 二進位字串 | binary, varbinary, image |
| 其他 | cursor, timestamp/rowversion, sql_variant, uniqueidentifier, table, xml |
| 類型 | 範圍 | 儲存 |
|---|---|---|
| bigint | -2^63 ~ 2^63-1 | 8 bytes |
| int | -2^31 ~ 2^31-1 | 4 bytes |
| smallint | -32,768 ~ 32,767 | 2 bytes |
| tinyint | 0 ~ 255 | 1 byte |
| bit | 0, 1, NULL | 1 byte (8欄位共用) |
| decimal(p,s) / numeric(p,s) | -10^38+1 ~ 10^38-1 | 依精度 5~17 bytes |
| money | -922,337,203,685,477.5808 ~ 922,337,203,685,477.5807 | 8 bytes |
| smallmoney | -214,748.3648 ~ 214,748.3647 | 4 bytes |
注意: decimal 與 numeric 功能相同,p(精度) 最大 38,預設 18;s(小數位) 0~p,預設 0。
| 類型 | 範圍 | 儲存 |
|---|---|---|
| float(n) | ±1.79E+308 ~ ±2.23E-308 | 視 n (1~53) 而定,預設 53 (8 bytes) |
| real | ±3.40E+38 ~ ±1.18E-38 | 4 bytes (相當 float(24)) |
| 類型 | 範圍 | 精度 | 儲存 |
|---|---|---|---|
| datetime | 1753-01-01 ~ 9999-12-31 | 3.33 ms | 8 bytes (兩個 4-byte 整數) |
| smalldatetime | 1900-01-01 ~ 2079-06-06 | 1 分鐘 | 4 bytes (兩個 2-byte 整數) |
| 類型 | 最大長度 | Unicode | 備註 |
|---|---|---|---|
| char(n) | 8,000 | 否 | 固定長度 |
| varchar(n|max) | 2^31-1 bytes | 否 | 可變長度,建議用 varchar(max) 替代 text |
| text | 2^31-1 chars | 否 | 已棄用 |
| nchar(n) | 4,000 | 是 | 固定長度,2 bytes/字元 |
| nvarchar(n|max) | 2^31-1 bytes | 是 | 可變長度,建議用 nvarchar(max) 替代 ntext |
| ntext | 2^30-1 chars | 是 | 已棄用 |
| 類型 | 最大長度 | 備註 |
|---|---|---|
| binary(n) | 8,000 | 固定長度 |
| varbinary(n|max) | 2^31-1 bytes | 可變長度,建議用 varbinary(max) 替代 image |
| image | 2^31-1 bytes | 已棄用 |
rowversion 為標準同義詞NEWID() 產生,僅支援比較運算專案支援多國語言請優先使用 nchar/nvarchar,避免字碼頁轉換問題。