MS SQL data Type comparison

Source: Internet
Author: User

  1. String data type

    Char
    This data type can be stored1~8000a fixed-length string, the string length is specified at creation time, or, if unspecified, the default ischar (1). Each character occupies1bytestorage space.
    NChar
    This data type can be stored1~4000a fixed lengthUnicodestring, the length of the string is specified at creation time, or, if unspecified, by defaultnchar (1). Each character occupies2bytesstorage space.
    varchar
    This data type can store a maximum value of8000a variable-length string of characters. The maximum length of a variable-length string is specified at creation time, such asvarchar (+), each character occupies1bytestorage space.
    nvarchar
    This data type can store a maximum value of4000variable length of charactersUnicodestring. Variable lengthUnicodeThe maximum length of a string is specified at creation time, such asnvarchar (+), each character occupies2bytesstorage space.
    Text
    This data type can store a maximum value of2147483647characters, and you do not have to specify its initial value, each character occupies a1bytestorage space, typically used to store large sections of an article. textThe data type is actually aLarge Objectdata type, by default, this type of data is not stored in the data row, but is stored in a separateLarge Objecton the data page. In addition,textThe data type cannot be used as a parameter in a function, stored procedure, or trigger.
    ntext
    Withtextdata type, except that the maximum value stored is1073741823Characters ofUnicodevariable length text, each character occupies1bytestorage space.

    Note: String values must be enclosed in quotation marks regardless of the string data type used, and single quotation marks are recommended.

Each character type differs:
CHAR,NCHAR fixed length, high speed, occupy space, need to handle
VARCHAR,NVARCHAR,TEXT variable length, small space, slow speed, no processing
NCHAR,NVARCHAR,NTEXT processing Unicode codes

2.Numeric data type

Bit
This data type stores a value of0or1Binary field. Occupy1bytestorage space.

tinyint
This data type stores0~255an integer that occupies1bytestorage space.

smallint
This data type stores-32768~32767an integer that occupies2bytesstorage space.

Int
This data type stores-2147483648~2147483647an integer that occupies4bytesstorage space.

bigint
This data type stores-9223372036854775808~9223372036854775807an integer that occupies8bytesstorage space.

Decimal/numeric
These two data types feature the same features, all of which are floating-point values that store a variable precision. But it is recommended to usedecimal, because the data it stores is "more descriptive". This data type is determined by a value of twodecimal (p,s),Pfor Precision,sis a scalar, such asdecimal (3,2), where the value2is the number of decimal places, thendecimal (3,2)can be used to store such1.28such a floating-point number. The storage space that this data type occupies depends on the precision valueP. Pto be1~9, Occupy5bytesstorage space;Pto be10~19, Occupy9bytesstorage space;Pto be20~28, Occupy13bytesstorage space;Pto be29~38, Occupy17bytesstorage space.

Float
This data type stores1~53floating-point value of variable precision, expressed asfloat (n),Nindicates the mantissa of the scientific notation, and the value range is-1.79e+308~-2.23e-308the negative and2.23e-308~1.79e+308a positive number. The storage space is determined by the precision value,Nto be1~24, Occupy4bytesstorage space;Nto be25~53, Occupy8bytesstorage space.

Real
This data type stores-3.40e+38~-1.18e-38the negative and1.18e~3.40e+38a positive number. Occupy4bytesstorage space.

SmallMoney
This data type stores-214748.3648~214748.3647the value of the currency, exactly after the decimal4bit. Occupy4bytesstorage space.

Money
This data type stores-922337203685477.5808~922337203685477.5807the value of the currency, exactly after the decimal4bit. Occupy8bytesstorage space.

3.Date and time data types

smalldatetime
This data type stores the1900years1Month1Day to2079years6Month6date of the day. Occupy4btyesstorage space.

Datetime
This data type stores the1753years1Month1Day to9999years AMonth todate of the day. Occupy8bytesstorage space.

4.Binary data Types

Binary
This data type stores1~8000characters, the specified length is the occupied storage space.

varbinary
This data type stores variable-length binary data that can be specified at the time of creation or unspecified.

5.Other data Types

Rowversion/timestamp
The two data types feature the same, butMicrosoftin any case, it is advisable to indicate asrowversionand nottimestamp, becauserowversionmore accurately reflects the true nature of the data type. timestampThe data type is completely unrelated to time, which indicates the relative order in which data modifications in the database occur. Do not use in keys (especially primary keys)timestampcolumn, because each time the row is modified,timestampvalues will change. When the specified data type isrowversionortimestamp, thenSQL Serverautomatically generates a new value when updating operations such as inserting or deleting a table, and putting the new value in the appropriate field. This type of data occupies8bytesstorage space.

uniqueidentifier
This type of data stores a binary value that acts as a globally unique identifier(GUID)The same. GUIDIt is primarily used to assign identifiers that must be unique in a network with multiple nodes and multiple computers. Occupy16bytesstorage space.

SQL and C # type comparison table

Serial number

Category

Sql

C#

Note

1

Integer

Bit

Boolean

True converts to 1,False to 0

2

tinyint

Byte

C # data types are located in the System namespace

3

smallint

Int16

4

Int

Int32

5

bigint

Int64

6

SmallMoney

Decimal

7

Money

Decimal

8

Numeric

Decimal

9

Decimal

Decimal

10

Floating point number

Float

Double

11

Real

Single

12

Date and time

smalldatetime

Datetime

13

Datetime

Datetime

14

Timestamp

Datetime

15

String

Char

String

16

Text

String

17

varchar

String

18

NChar

String

19

ntext

String

20

nvarchar

String

21st

Binary data

Binary

Byte[]

22

varbinary

Byte[]

23

Image

Byte[]

24

Other

uniqueidentifier

Guid

25

Variant

Object

MS SQL data Type comparison

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.