SQL Server data types

Source: Internet
Author: User
Tags ranges

First, the chart

Character string:

Unicode string:

Binary Type:

Number Type:

Date Type:

Other data types:

Second, the basic classification

First big class: Integer data

The--bit:bit data type represents 0,1 or null, which means true,false. Consumes 1byte.
--int: Stores the positive and negative numbers in 4 bytes. Storage range: -2^31 to 2^31-1.
--smallint: Stores the positive and negative numbers in 2 bytes. Storage range: -2^15 to 2^15-1
--tinyint: Is the smallest integer type, with only 1 bytes, range: 0 so ^8-1

Second class: Accurate numerical data

--numeric: The number represented can reach 38 bits, and the number of bytes used to store the data varies with the number of bits used for use.
--decimal: Similar to numeric

Class Three: Approximate floating-point numeric data

--float: Stores data in 8 bytes. Can be up to 53 bits. Range: -1.79E+308 to 1.79E+308.
--real: 24 digits, 4 bytes, numeric range: -3.04E+38 to 3.04E+38

Fourth Category: Date-time data

--datatime: Indicates that the time range can be expressed from 1753/1/1 to 9999/12/31, time can be expressed to 3.33/1000 seconds. Use 8 bytes.
--smalldatetime: Indicates that the time range can be expressed from 1900/1/1 to 2079/12/31. Use 4 bytes.

Category five: String data

--char: The length is set, the shortest is 1 bytes, and the maximum is 8,000 bytes. The insufficient length will be blank.
--varchar: The length is also set, the shortest is 1 bytes, the longest is 8,000 bytes, the trailing blanks will be removed.
--text: Long-width is also set, the longest can be stored 2G of data.

Category six: Unincode string data

--nchar: The length is set, the shortest is 1 bytes, and the maximum is 4,000 bytes. The length of the gap is blank. Storing one character requires 2 bytes.
--nvarchar: The length is set, the shortest is 1 bytes, and the maximum is 4,000 bytes. The trailing blanks are removed. Storing one character requires 2 bytes.
--ntext: The length is set, the shortest is 1 bytes, the longest is 2G. The trailing blanks are removed and 2 bytes are required to store a single character.

Seventh Category: Currency data types

--money: The recorded amount ranges from 92233720368577.5808 to 92233720368577.5807. Requires 8 bytes.
--smallmoney: The recorded amount ranges from 214748.3648 to 214748.36487. Requires 4 bytes.

Eighth Class: Tag data

--timestamp: This data type is unique in every table! When one record in the table changes, the timestamp field of the record is automatically updated.
--uniqueidentifier: The only record used to identify many tables within a database.

Nineth Category: Binary character string data

--binary: fixed-length binary code string field with a minimum of 1 and a maximum of 8000.
--varbinary: With binary difference is the data tail is 00 o'clock, varbinary will remove it
--image: A variable-length binary string with a maximum of 2G.

Third, frequently asked questions

the difference between varchar and nvarchar:

--varchar (n): variable-length, non-Unicode character data with a length of n bytes. n must be a numeric value between 1 and 8,000. Storage size is the actual length of bytes of input data, not n bytes.

--Single byte data with varchar

--nvarchar (n): A variable-length Unicode character data that contains n characters. The value of n must be between 1 and 4,000. The storage size of bytes is twice times the number of characters entered.

--Double byte with nvarchar
Example: Two fields have field values: me and coffee
The varchar field accounts for 2x2+6=10 bytes of storage, while the nvarchar field accounts for 8x2=16 bytes of storage space.

--If the field value is only available in English, you can choose varchar, and there are more double byte (Chinese, Korean, etc.) characters in the field value with nvarchar

SQL Server data types

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.