Developing common data types in SQL Server

Source: Internet
Author: User

In our daily development process, when designing a database, we often encounter problems with selecting data types, choosing what type of data is most appropriate, and then choosing the corresponding CLR type when we create the corresponding entity in the project. In response to these questions, this article was born.

SQL Server data types Number of bytes occupied Representation Range The corresponding CLR type Applicable scenarios
Char CHAR (n) System.String Use char (2) to represent a type or state (tinyint is recommended instead)
varchar VARCHAR (n) 1~8000 System.String A string containing only English characters
nvarchar nvarchar (n) 1~4000 System.String A string containing Chinese characters
Int 4 bytes 2,147,483,648 to 2,147,483,647 System.Int32 Represents an integer, such as a self-increment ID
bigint 8 bytes 9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 System.Int64 (Long) Represents a long integer, such as a self-increment ID (with a large number of cases)
Decimal 5~17 bytes System.Decimal Amount
tinyint 1 bytes 0~255 System.Byte Type and state, better than char (2) extensibility
Bit 0,1 or null System.Boolean Generally used to indicate yes and no two situations
Datetime 8 bytes January 1, 1753 to December 31, 9999 System.DateTime Represents a date and time
Time System.TimeSpan Represents a time interval, such as timing
varbinary   system.byte
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.