data types for SQL Server

Source: Internet
Author: User

1.char (n) and varchar (n):

Store non-Unicode character data, n for byte length, n must be a numeric value between 1 and 8,000, except that char (n) stores a fixed-length, n-sized byte, and varchar (n) stores the actual length of the input data, but the maximum length cannot exceed N.

2.nchar (n) and nvarchar (n):

Store Unicode character data (Unicode all characters are represented by two bytes, i.e. the English character is also represented in two bytes), n is the character length, n must be a number between 1 and 4,000, except that nchar (n) stores a fixed length of n*2 bytes nvarchar (n) stores the actual length of the input character * 2 bytes but the maximum length of the input character cannot exceed N.

3.text and ntext:

Text stores variable-length non-Unicode data with a maximum length of 2^31-1 (2,147,483,647) bytes; ntext stores variable-length Unicode data with a maximum length of 2^30-1 (1,073,741,823) characters.

4.varchar (max) and text with nvarchar (max) and ntext:

The role of varchar (max) and nvarchar (max) is equivalent to the fact that text and Ntext,varchar (max) can store up to 2G of data (later versions may be more), but text and ntext do not support "=", "Left ()" , like, and varchar (max) and nvarchar (max) support, and Microsoft may remove the text and ntext types in SQL Server later, you should use varchar (max) and nvarchar (max) Replace text and ntext.

5.datetime and smalldatetime:

DateTime: Date and Time data from January 1, 1753 to December 31, 9999, accurate to 3% seconds.
smalldatetime: Date and time data from January 1, 1900 to June 6, 2079, accurate to minutes.

6.bitint, int, smallint, tinyint, and bit:

bigint: Integer data from -2^63 (-9223372036854775808) to 2^63-1 (9223372036854775807).
int: integer data from -2^31 (-2,147,483,648) to 2^31-1 (2,147,483,647).
smallint: Integer data from -2^15 (-32,768) to 2^15-1 (32,767).
Tinyint: Integer data from 0 to 255.
Bit:1 or 0 of integer data.

7.decimal and numeric:

Decimal and numeric are equivalent, the decimal data type can store up to 38 digits, all numbers can be placed to the right of the decimal point, and the two attributes that define the columns, variables, and parameters of a decimal are as follows:
P: The sum of the digits to the left and right of the decimal point, excluding the decimal point; s: Specifies the number of decimal places or numbers that can be placed to the right of the decimal point;
such as 123.45, then p=5,s=2.
P and S must comply with the following rules: 0 <= s <= P <= 38.

8.float and Real:

float: Floating-point numeric data from -1.79^308 to 1.79^308.
Real: Floating-point numeric data from -3.40^38 to 3.40^38. In SQL Server, the synonym for Real is float (24).

9. Internationalization:

The simplest way to manage character data in an international database is to always use the Unicode nchar, nvarchar, and nvarchar (max) data types without using their corresponding non-Unicode data types: char, varchar, and text. In this way, the client will have the same characters as the data that all other clients see. If all applications using international databases also use Unicode variables in place of non-Unicode variables, character conversions do not need to be performed anywhere in the system.

data types for 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.