SQL Server Field type description _ database Other

Source: Internet
Author: User
Tags integer numbers numeric
Description provided by SQL Server.

Integer number of bit:0 or 1
int: integer numbers from -2^31 (-2,147,483,648) to 2^31 (2,147,483,647)
smallint: integer numbers from -2^15 (-32,768) to 2^15 (32,767)
tinyint: integer numbers from 0 to 255

Decimal: Number of fixed and significant digits from -10^38 to 10^38-1
A synonym for Numeric:decimal.

Money: Currency data from -2^63 ( -922,337,203,685,477.5808) to 2^63-1 (922,337,203,685,477.5807), minimum currency unit 10 per thousand
SmallMoney: Currency data from -214,748.3648 to 214,748.3647, minimum currency unit 10 per thousand

float: Numbers from -1.79E+308 to 1.79E+308 variable precision
Real: Variable precision numbers from -3.04E+38 to 3.04E+38

DateTime: Date and Time data from January 1, 1753 to 9999 12th 31, minimum unit of time 3% seconds or 3.33 milliseconds
smalldatetime: Date and time data from January 1, 1900 to June 6, 2079, minimum time unit is minutes

Timestamp: timestamp, a unique number of database widths
UniqueIdentifier: Global Unique identifier GUID

Char: fixed-length non-Unicode character data with a maximum length of 8000
VARCHAR: variable-length character data with non-Unicode maximum length of 8000
Text: variable length non-Unicode character data with a maximum length of 2^31-1 (2G)

NCHAR: Character-type data for fixed-length Unicode with a maximum length of 8000
NVARCHAR: variable length Unicode character data with a maximum length of 8000
NTEXT: variable length Unicode character data with a maximum length of 2^31-1 (2G)

Binary: fixed-length binary data with a maximum length of 8000
VARBINARY: variable-length binary data with a maximum length of 8000
Image: Variable-length binary data with a maximum length of 2^31-1 (2G)

Introduction

MS SQL Server is made up of five commonly used fields, character, text, numeric, logical, and date! Many friends are suffering from the BBS in Access to convert to SQL after the field type mismatch and overwhelmed, let's introduce some of these five data types of their respective characteristics!

Body

[1] Character type data Varchar,char type

In the program when you need to store a relatively short string information, we will use character data, SQL character data and there are two types! varchar and char, the difference between two types of data is very subtle, but it is very important!

For example, when you enter a string of length 4 in a 40-character varchar field and then TOL8 the data you remove, the length of the data is 4 characters, and you change the varchar to a char, and you take out the data for the length of the 40 characters, strings are appended with extra spaces, such as TOL8 only 4 characters, then the data taken from Char is TOL8 plus 36 spaces! In the specific program design I personally recommend varchar type, because from some references I found that the varchar type is less than char consumption of hard disk memory!

The varchar store is up to 255 characters long, and it takes more than this length to use the text data we're going to talk about here.

[2] Literal data text

You can store more than 2 billion strings in text-type data, how about this big enough? But also is not at any time is and uses the text type data, because he occupies the space very much, also consumes the server very much, everywhere chaos uses the consequence to be unimaginable! Because even if you enter a null value like a text field, he will occupy 2K of space! And then there is no other way to reclaim space than to delete the data!

[3] Data-type data int,tinying,numeric

SQL supports a variety of different data types so that you can store integers, decimals, and money!

INT (integer data) indicates a range of integers from-2,147,483,647 to 2,147,483,647

If your value is not that long, in order to save memory space you can use smallint its representation range is-32768 to 32768 integers! They are used in exactly the same way!

If you want to save space, you can choose to use tinyint. He can only store 0 to 255 integers note tinyint cannot store negative numbers, one tinyint occupies one byte, and one int data occupies 4 bytes!

[4] Data-type data Bit

Web page check box collection information stored in the database, is the most common use of bit type! He only has two values: 0 or 1.

[5] Data-type data datetime,samlldatetime

The datetime storage range is from the first millisecond of January 1, 1753 to the last millisecond of December 31, 9999, if you do not need coverage of such a large date range, optional use of smalldatetime type its storage range is from January 1, 1900 to June 6, 2079, But only in seconds!

[6] Special type data Cursor

Here are some 2 data types and some other infrequently used data types, and I won't say more!
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.