Common Data Types in SQL Server: SQL Server Data Types

Source: Internet
Author: User

Common Data Types in SQL Server: SQL Server Data Types

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

Bit integer
The bit 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, No, True, False, On, or Off.

Note: a data type that saves a lot of space. If you can meet your needs, use it as much as possible.

 

Tinyint integer
The tinyint data type can store integers ranging from 0 to 255. It is useful when you only plan 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 secure and does not accept the embedding of malicious script content.

 

Smallint integer
The smallint data type can store integers between the 15 power (-32768) of-2 and the 15 power (32767) of 2. This type of data 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 to meet your needs, you can consider using smallintType, because this type is relatively secure and does not accept malicious script content embedding. 

 

Int integer
The int data type can store integers from the 31 Power (-2147483648) of-2 to the 31 Power (2147483 647) of 2. This type can be used for almost all numeric data stored in the database. This data type occupies 4 bytes in the database.

NOTE: If smallint does not meet your requirements, you can consider using a larger int type.

Decimal exact numeric type
The decimal data type can be used to store the fixed precision and range of numeric data of 38 power-1 to 10 from-10. When using 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 exact numeric type
The numeric data type is similar to decimal.

Smallmoney currency type
The smallmoney data type is used to indicate money and currency values. This data type can store data from-214748.3648 to 214748.3647, accurate to one thousandth of the currency unit

Money currency type
The money data type is used to indicate money and currency values. This data type can store data from-922 billion to 922 billion, accurate to one thousandth of the currency unit

Float approximate numeric type
Float data is an approximate value type for floating point numbers. Floating Point Numbers are similar because not all numbers in the range can be accurately expressed. Floating Point number can be any number from-1.79E + 308 to 1.79E + 308

Real approximate numeric type
The real data type is similar to a floating point number and is an approximate value type. It indicates the floating point number between-3.40E + 38 and 3.40E + 38.

Smalldatetime datetime type
The smalldatetime data type is used to indicate the date and time from January 1, January 1-20, 1900 to January 1, June 6, accurate to one minute.


Datetime type
The datetime data type is used to represent the date and time. This data type stores all the date and time data from January 1, 1/300, accurate to 3.33 seconds or milliseconds.

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

Timestamp Special Data Type
The timestamp data type is a special data type used to create a unique digital within the database range. A table can have only one timestamp column. The value of the timestamp column changes each time a row is inserted or modified. Although its name contains "time", 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 (GUID. GUID is indeed globally unique. This number has almost no chance of being rebuilt in another system. You can use the NEWID function or convert a string to be unique.
Identifier to initialize a column with a unique identifier.

Char character type
The char data type is used to store non-uniform encoded data with a fixed 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 zip code and 4 character format, you know that it always takes 10 characters. The column width of this data type is up to 8000 characters.

Varchar character-type varchar data type, which is the same as char type, used to store non-uniform encoding character data. Unlike char, the data type is variable. When defining a column as the data type, you must specify the maximum length of the column. The biggest difference between it and char data types is that the storage length is not the column length, but the data length.

Text character type
The text data type is used to store a large amount of non-uniform encoding character data. This data type can contain a maximum of 2 billion to characters.

Nchar unified encoding type
The nchar data type is used to store fixed-length, unified encoding data. Unified encoding uses a dual-byte structure to store each character, rather than a single byte (in common text ). It allows a large number of extended characters. This data type can store 4000 characters, doubling the byte space used.

Nvarchar uniform encoding type
The nvarchar data type is used as a variable-length uniform encoding type data. This data type can store 4000 characters, and the byte space is doubled.

Ntext unified encoding type
The ntext data type is used to store a large amount of uniform encoding data. This data type can store 230-1 or nearly 1 billion characters, and the byte space is doubled.

Binary data type
The binary data type is used to store binary data that can be up to 8000 bytes in length. This data type should be used when the input table content is close to the same length.

Varbinary binary data type
The varbinary data type is used to store up to 8000 bytes of long binary data. This type of data should be used 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 2 billion-1-1 or approximately bytes.

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.