MSSQL data type and length restrictions

Source: Internet
Author: User

SQL Server provides a system data type set that defines all data types that can be used with SQL Server. The following lists the data type sets provided by the system.

You can define a user-defined data type, which is the alias of the Data Type provided by the system. For more information about user-defined data types, see sp_addtype and create user-defined data types.
When two expressions with different data types, sorting rules, precision, decimal places, or lengths are combined using operators:
Apply the Data Type precedence rule to the Data Type of the input expression to determine the Data Type of the obtained value. For more information, see Data Type precedence.

If the data type of the result is char, varchar, text, nchar, nvarchar, or ntext, the sorting rule of the result value is determined by the priority rule of the sorting rule. For more information, see sorting rule priority.

The precision, decimal places, and length of the result depend on the precision, decimal places, and length of the input expression. For more information, see precision, decimal places, and length.
SQL Server provides a synonym for data types for SQL-92 compatibility. For more information, see Data Type synonyms.

Exact number

Integer

Bigint integer data from-2 ^ 63 (-9223372036854775808) to 2 ^ 63-1 (9223372036854775807) (All numbers ).

Int integer data from-2 ^ 31 (-2,147,483,648) to 2 ^ 31-1 (2,147,483,647) (All numbers ).

Smallint integer data from-2 ^ 15 (-32,768) to 2 ^ 15-1 (32,767.

Integer Data of tinyint from 0 to 255.

Bit

Integer Data of bit 1 or 0.

Decimal and numeric

Decimal numeric data with fixed precision and decimal places from-10 ^ 38 + 1 to 10 ^ 38-1.

Numeric functions are equivalent to decimal.

Money and smallmoney

The value of money data is between-2 ^ 63 (-922,337,203,685,477.5808) and 2 ^ 63-1 (+ 922,337,203,685,477.5807), accurate to 10 of the monetary unit.

The value of smallmoney is between-214,748.3648 and + 214,748.3647, accurate to 10 thousandth of the monetary unit.

Approximate Number

Float is a floating point number ranging from-1.79E + 308 to 1.79E + 308.

Real is a floating point number ranging from-3.40E + 38 to 3.40E + 38.

Datetime and smalldatetime

Datetime is accurate to January 1-9, 1753 seconds (or December 31, 999 milliseconds) from the date and time data of January 1, 3%, 3.33 ).

Smalldatetime is accurate to minutes from the date and time data from January 1, January 1-20, 1900 to January 1, June 6.

String

The data of non-Unicode characters with a fixed char length. The maximum length is 8,000 characters.

The variable-length non-Unicode data of varchar. It can contain a maximum of 8,000 characters.

Non-Unicode data with variable text length. The maximum length is 2 ^ 31-1 (2,147,483,647) characters.

Unicode string

Unicode data with a fixed nchar length. The maximum length is 4,000 characters.

The nvarchar variable-length Unicode data. Its maximum length is 4,000 characters. Sysname is a user-defined data type provided by the system. It is functionally equivalent to nvarchar (128) and is used to reference the database object name.

The ntext variable-length Unicode data. The maximum length is 2 ^ 30-1 (1,073,741,823) characters.

Binary string

Binary is a fixed-length binary data with a maximum length of 8,000 bytes.
Varbinary is a variable-length binary data with a maximum length of 8,000 bytes.
A variable-length binary data. The maximum length is 2 ^ 31-1 (2,147,483,647) bytes.

Other data types

Cursor reference.

SQL _variant
A data type that stores various data types supported by SQL Server (except for text, ntext, timestamp, and SQL _variant.

Table
A special data type that stores post-processing result sets.

Timestamp
The unique number in the database range, which is also updated each time the row is updated.

Uniqueidentifier
GUID ).

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.