SQL数据类型是一个属性,该属性指定的任何对象的数据类型。在SQL中的每一列,变量和表达式相关的数据类型。
在创建表时,你会使用这些数据类型。会根据需要为表列中选择一个特定的数据类型。
SQL Server提供的数据类型供您使用的六大类:
精确数字数据类型:
近似数值数据类型:
日期和时间数据类型:
字符串数据类型:
Unicode字符串数据类型:
二进制数据类型:
其他数据类型:
在创建表时,你会使用这些数据类型。会根据需要为表列中选择一个特定的数据类型。
SQL Server提供的数据类型供您使用的六大类:
精确数字数据类型:
|
数据类型
|
FROM
|
TO
|
| bigint | -9,223,372,036,854,775,808 | 9,223,372,036,854,775,807 |
| int | -2,147,483,648 | 2,147,483,647 |
| smallint | -32,768 | 32,767 |
| tinyint | 0 | 255 |
| bit | 0 | 1 |
| decimal | -10^38 +1 | 10^38 .1 |
| numeric | -10^38 +1 | 10^38 .1 |
| money | -922,337,203,685,477.5808 | +922,337,203,685,477.5807 |
| smallmoney | -214,748.3648 | +214,748.3647 |
近似数值数据类型:
|
DATA TYPE
|
FROM
|
TO
|
| float | -1.79E + 308 | 1.79E + 308 |
| real | -3.40E + 38 | 3.40E + 38 |
日期和时间数据类型:
|
数据类型
|
FROM
|
TO
|
| datetime | Jan 1, 1753 | Dec 31, 9999 |
| smalldatetime | Jan 1, 1900 | Jun 6, 2079 |
| date | Stores a date like June 30, 1991 | |
| time | Stores a time of day like 12:30 P.M. | |
注: 在此日期时间3.33毫秒精度为smalldatetime有1分钟的准确性。
字符串数据类型:
|
数据类型
|
FROM
|
TO
|
| char | char | Maximum length of 8,000 characters.( Fixed length non-Unicode characters) |
| varchar | varchar | Maximum of 8,000 characters.(Variable-length non-Unicode data). |
| varchar(max) | varchar(max) | Maximum length of 231characters, Variable-length non-Unicode data (SQL Server 2005 only). |
| text | text | Variable-length non-Unicode data with a maximum length of 2,147,483,647 characters. |
Unicode字符串数据类型:
|
数据类型
|
描述
|
| nchar | Maximum length of 4,000 characters.( Fixed length Unicode) |
| nvarchar | Maximum length of 4,000 characters.(Variable length Unicode) |
| nvarchar(max) | Maximum length of 231characters (SQL Server 2005 only).( Variable length Unicode) |
| ntext | Maximum length of 1,073,741,823 characters. ( Variable length Unicode ) |
二进制数据类型:
|
数据类型
|
描述
|
| binary | Maximum length of 8,000 bytes(Fixed-length binary data ) |
| varbinary | Maximum length of 8,000 bytes.(Variable length binary data) |
| varbinary(max) | Maximum length of 231 bytes (SQL Server 2005 only). ( Variable length Binary data) |
| image | Maximum length of 2,147,483,647 bytes. ( Variable length Binary Data) |
其他数据类型:
|
数据类型
|
描述
|
| sql_variant | 存储各种SQL Server支持的数据类型值,除了text,ntext,和时间戳 |
| timestamp | 存储一个数据库范围内的唯一号码得到更新,每一次一行得到更新 |
| uniqueidentifier | 存储一个全局唯一标识符(GUID) |
| xml | 存储XML数据。可以将XML实例存储在一列或变量(只在SQL Server 2005) |
| cursor | 引用一个游标对象 |
| table | 引用一个游标对象 |
本文详细介绍了SQLServer中六种主要的数据类型,包括精确数字、近似数值、日期时间、字符串、Unicode字符串及二进制数据类型等,并列举了每种类型的取值范围。
5184

被折叠的 条评论
为什么被折叠?



