Transfer: Analysis of various data types of Sql Server

Reprint link: http://www.cnblogs.com/andy_tigger/archive/2011/08/21/2147745.html

Reprinted content:

1 bit: Integer
bit The data type is an integer, and its value can only be 0, 1 or null. This data type is used to store data with only two possible values, such as Yes or No, True or False, On or Off.  
Note: It is a data type that saves space, and should be used as much as possible if it can meet the needs.

2 tinyint: integer
tinyint data type can store integers from 0 to 255. It is useful when you only intend to store a limited number of values. This data type occupies 1 byte in the database.
Note: If the bit type is too monotonous to meet your needs, you can consider using the tinyint type, because this type is relatively safe and does not accept the embedding of malicious script content.

3 smallint: Integer 
The smallint data type can store integers from -2 to the 15th power (-32768) to 2 to the 15th power (32767). This data type is useful for storing numeric data that is often limited to a specific range. This data type occupies 2 bytes of space in the database.
Note: If the tinyint type is too monotonous for your needs, you can consider using the smallint type, because this type is relatively safe and does not accept the embedding of malicious script content.

4 int: Integer
The int data type can store integers from -2 to the 31st power (-2147483648) to 2 to the 31st power (2147483 647). This data type can be used for almost any numeric data stored in the database. This data type occupies 4 bytes in the database.
Note: If smallint does not meet your needs, you can consider using a larger int type.

5 decimal: exact numeric type
The decimal data type can be used to store numeric data of fixed precision and range from -10 to the 38th power -1 to 10 to the 38th power -1. When using this data type, the range and precision must be specified. The range is the total number of digits that can be stored around the decimal point. The precision is the number of digits stored to the right of the decimal point.

6numeric: The exact
numeric numeric data type is similar to decimal.

7smallmoney: Currency The
smallmoney data type is used to represent money and monetary values. This data type can store data from -214748.3648 to 214748.3647, accurate to one ten-thousandth of a currency unit.

money: The currency
money data type is used to represent money and currency values. This data type can store data from -922 billion to 922 billion, accurate to one ten-thousandth of a monetary unit. 

9 float: Approximate numeric           
The float data type is an approximate numeric type for floating-point numbers. Floating-point numbers are said to be approximate because not all numbers within their range can be represented exactly. Floating point numbers can be any number from -1.79E+308 to 1.79E+308

10 real: approximate numeric          
real data types, like floating point numbers, are approximate numeric types. It can represent floating-point numbers with values ​​between -3.40E+38 and 3.40E

+         
38 time, accurate to one minute 

12 datetime: datetime type         
The datetime data type is used to represent dates and times. This data type stores all date and time data from January 1, 1753 to December 31, 9999, accurate to three hundredths of a second or 3.33 milliseconds.

13 cursor: special data type
cursor data type is a A special data type that contains a reference to a cursor. This data type is used in stored procedures and cannot be used when creating tables.

14 timestamp: special data type         
timestamp data type is a special data type used to create a database-wide unique number. There can only be one timestamp column in a table. Every time a row is inserted or modified, the value of the timestamp column changes. Despite having "time" in its name, the timestamp column is not a human-recognized date. In a database, the timestamp value is unique 

15 Uniqueidentifier: Special data type         
Uniqueidentifier data type is used to store a globally unique identifier, that is, GUID. GUIDs are indeed globally unique. This number has little chance of being reconstructed in another system. You can use the NEWID function or convert a string to a unique identifier to initialize a column with a unique identifier.

16 char: The character             
char data type is used to store fixed-length non-uniform coded data of a specified length. When defining a column of this type, you must specify the column length. This data type is useful when you always know the length of the data to be stored. For example, when you store data in the ZIP code plus 4 character format, you know that 10 characters will always be used. The column width for this data type is up to 8000 characters.

varchar 字符型varchar数据类型,同char类型一样,用来存储非统一编码型字符数据。与char 型不一样,此数据类型为变长。当定义一列为该数据类型时,你要指定该列的最大长度。 它与char数据类型最大的区别是,存储的长度不是列长,而是数据的长度   .

17 text:字符型             
text 数据类型用来存储大量的非统一编码型字符数据。这种数据类型最多可以有231-1或20亿个字符.

18 nchar:统一编码字符型  
nchar 数据类型用来存储定长统一编码字符型数据。统一编码用双字节结构来存储每个字符,而不是用单字节(普通文本中的情况)。它允许大量的扩展字符。此数据类型能存储4000种字符,使用的字节空间上增加了一倍.

19 nvarchar:统一编码字符型   
nvarchar 数据类型用作变长的统一编码字符型数据。此数据类型能存储4000种字符,使用的字节空间增加了一倍.

20 ntext:统一编码字符型   
ntext 数据类型用来存储大量的统一编码字符型数据。这种数据类型能存储230 -1或将近10亿个字符,且使用的字节空间增加了一倍

21 binary:二进制数据类型  
binary数据类型用来存储可达8000 字节长的定长的二进制数据。当输入表的内容接近相同的长度时,你应该使用这种数据类型.

22 varbinary:二进制数据类型  
varbinary 数据类型用来存储可达8000 字节长的变长的二进制数据。当输入表的内容大小可变时,你应该使用这种数据类型 

23 image:二进制数据类型
image 数据类型用来存储变长的二进制数据,最大可达231-1或大约20亿字节 

 

注意:
1) 对于数值型数据类型,宽度(scale)是指存储在小数点后的数字位数,而精度(precision)是指能存储的包含小数点在内的所有数字位数。
2) money和small money的存储宽度为4。
3) 时间戳列值在每一行更新时系统自动更新,时间戳列不能是关键字或关键字的一部分。
4) 唯一标识数据类型不能使用算术操作符(如+、-等),这种数据类型只能使用相等比较操作。Unicode是所有字符集的一致存储数据的标准。它要使用两倍于非Unicode数据存储的存储空间。

 

PS:个人只是转载了一部分,更多更详细的解析请查看原文

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326570891&siteId=291194637