Common data types in SQL Server

Source: Internet
Author: User

Go to http://www.cnblogs.com/andy_tigger/archive/2011/08/21/2147745.html

Bit integral type
The bit data type is integral, and its value can only be 0, 1, or null. This data type is used to store data that has only two possible values, such as Yes or No, True or false, on, or off.

Note: A data type that is space-saving and should be used as much as possible if it satisfies the requirements.

tinyint integral type
The 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 bytes 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 embedding of malicious script content.

smallint integral type
The smallint data type can store integers from 15 powers (-32768) of 2 to 15 powers (32767) of 2. This data type is useful for storing numeric data that is often scoped to a specific range. This data type occupies 2 bytes of space in the database.

Note: If the tinyint type is too monotonous to meet your needs, you may want to consider using smallint type, because this type is relatively safe and does not accept embedding of malicious script content.

int integral type
The int data type can store integers from 2 to 31 powers (-2147483648) to 2 to 31 powers (2147483 647). Almost all numeric data stored in a database can be used with this data type. This type of data occupies 4 bytes in the database.

Note: If smallint is not able to meet your needs, you can consider using a larger int type.

Decimal exact numeric type
The decimal data type can be used to store numeric data of a fixed precision and range from 10 to 38 powers-1 to 10 of 38 power-1. When you use this data type, you must specify the range and precision. The range is the total number of digits that can be stored around the decimal point. Precision is the number of digits stored on the right of the decimal point

numeric precise numerical type
The numeric data type is similar to decimal.

SmallMoney currency type
The smallmoney data type is used to represent money and currency values. This data type can store data from 214748.3648 to 214748.3647, accurate to one out of 10,000 of the currency unit

Money currency type
The Money data type is used to denote monetary and currency values. This data type can store data from 922 billion to 922 billion, accurate to one out of 10,000 of the currency unit

float Approximate numerical type
The float data type is an approximate numeric type that is used by floating point numbers. It is said that the floating-point number is approximate, because not all the numbers in its range can be accurately represented. Floating-point numbers can be any number from -1.79E+308 to 1.79E+308

Real approximate numeric type
Real data types are approximate numeric types like floating-point numbers. It can represent a floating-point number between -3.40E+38 and 3.40E+38.

smalldatetime Date and Time type
The smalldatetime data type is used to represent the date and time from January 1, 1900 to June 6, 2079, accurate to one minute


DateTime Date-Time type
The datetime data type is used to represent the date and time. This data type stores all date and time data from January 1, 1753 to December 31, 9999, accurate to 1% seconds or 3.33 milliseconds.

Cursor Special Data type
The cursor data type is a special type of data that contains a reference to a cursor. This data type is used in stored procedures and cannot be used when creating tables

Timestamp Special Data type
The timestamp data type is a special type of data that is used to create a database-wide unique digital. There can be only one timestamp column in a table. Each time you insert or modify a row, the value of the timestamp column changes. Although it has "time" in its name, the timestamp column is not a date that people can recognize. In a database, the timestamp value is unique.

uniqueidentifier Special Data type
The uniqueidentifier data type is used to store a globally unique identifier, the GUID. The GUID is truly globally unique. This number has little chance of being rebuilt in another system. You can use the NEWID function or convert a string to a unique
Identifier to initialize the column with a unique identifier.

char character type
The char data type is used to store fixed-length, non-uniform encoded data of specified lengths. When you define a column for this type, you must specify a column length. This data type is useful when you always know the length of the data you want to store. For example, when you store data by zip code plus 4 character formatting, you know that you always need to use 10 characters. This data type has a maximum column width of 8,000 characters.

varchar character varchar data types, like char types, are used to store non-uniform encoded character data. Unlike the char type, this data type is variable length. When you define a column for that data type, you specify the maximum length of the columns. The biggest difference to the char data type is that the length of the stored data is not the length of the column.

Text character type
The text data type is used to store a large number of non-uniform encoded character data. This data type can have a maximum of 231-1 or 2 billion characters.

NCHAR Unified coded Character type
The nchar data type is used to store fixed-length, uniformly encoded character data. Uniform encoding uses a double-byte structure to store each character, rather than a single byte (in normal text). It allows for a large number of extended characters. This data type can store 4000 characters, which is used to increase the byte space by one times.

Nvarchar Unified coded character type
The nvarchar data type is used as a uniformly encoded character type data that is variable length. This data type can store up to 4000 characters, and the byte space used increases by one times.

ntext Unified coded character type
The ntext data type is used to store a large number of uniformly encoded character-type data. This data type can store 230-1 or nearly 1 billion characters, and the byte space used increases by one times

Binary binary data type
Binary data types are used to store fixed-length binary data up to 8000 bytes long. You should use this data type when the contents of the input table are close to the same length.

varbinary binary data types
The varbinary data type is used to store variable-length binary data up to 8000 bytes long. You should use this data type when the content size of the input table is variable

Image binary Data type
The image data type is used to store variable-length binary data up to 231-1 or approximately 2 billion bytes

Common data types in SQL Server

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.