SQL advanced (8) data type, SQL data type

Source: Internet
Author: User

SQL advanced (8) data type, SQL data type
SQL advanced (8) data type Character string:

Data Type Description Storage
Char (n) A fixed-length string. It can contain a maximum of 8,000 characters. N
Varchar (n) A variable-length string. It can contain a maximum of 8,000 characters.  
Varchar (max) A variable-length string. It can contain a maximum of 1,073,741,824 characters.  
Text A variable-length string. Up to 2 GB character data.  
Unicode string:
Data Type Description Storage
Nchar (n) Unicode data of a fixed length. It can contain a maximum of 4,000 characters.  
Nvarchar (n) Unicode data with a variable length. It can contain a maximum of 4,000 characters.  
Nvarchar (max) Unicode data with a variable length. It can contain a maximum of 536,870,912 characters.  
Ntext Unicode data with a variable length. Up to 2 GB character data.  
Binary type:
Data Type Description Storage
Bit 0, 1, or NULL  
Binary (n) Binary data of a fixed length. Up to 8,000 bytes.  
Varbinary (n) Variable Length binary data. Up to 8,000 bytes.  
Varbinary (max) Variable Length binary data. The maximum size is 2 GB.  
Image Variable Length binary data. 2 GB at most.  
Number Type:
Data Type Description Storage
Tinyint Allow all numbers from 0 to 255. 1 byte
Smallint Allow all numbers from-32,768 to 32,767. 2 bytes
Int Allow all numbers from-2,147,483,648 to 2,147,483,647. 4 bytes
Bigint All numbers between-9,223,372,036,854,775,808 and 9,223,372,036,854,775,807 are allowed. 8 bytes
Decimal (p, s)

Fixed Number of precision and proportion. A number ranging from-10 ^ 38 + 1 to 10 ^ 38-1 is allowed.

The p parameter indicates the maximum number of digits that can be stored (left and right of the decimal point ). P must be a value between 1 and 38. The default value is 18.

The s parameter indicates the maximum number of digits stored on the right of the decimal point. S must be the value between 0 and p. The default value is 0.

5-17 bytes
Numeric (p, s)

Fixed Number of precision and proportion. A number ranging from-10 ^ 38 + 1 to 10 ^ 38-1 is allowed.

The p parameter indicates the maximum number of digits that can be stored (left and right of the decimal point ). P must be a value between 1 and 38. The default value is 18.

The s parameter indicates the maximum number of digits stored on the right of the decimal point. S must be the value between 0 and p. The default value is 0.

5-17 bytes
Smallmoney Currency data between-214,748.3648 and 214,748.3647. 4 bytes
Money Currency data between-922,337,203,685,477.5808 and 922,337,203,685,477.5807. 8 bytes
Float (n) Floating precision digital data from-1.79E + 308 to 1.79E + 308. Parameter n indicates whether the field is 4-byte or 8-byte. Float (24) saves 4 bytes, while float (53) saves 8 bytes. The default value of n is 53. 4 or 8 bytes
Real Floating precision digital data from-3.40E + 38 to 3.40E + 38. 4 bytes
Date type:
Data Type Description Storage
Datetime The precision is January 1-9, 1753 milliseconds from January 1, December 31, 999 to January 1, 3.33. 8 bytes
Datetime2 From January 1-9, 1753 to December 31, 999, the precision was 100 nanoseconds. 6-8 bytes
Smalldatetime The precision is 1 minute from January 1, January 1-20, 1900 to January 1, June 6. 4 bytes
Date Only the date is stored. From January 1, January 1-9, 0001 to January 1, December 31, 999. 3 bytes
Time Only storage time. The precision is 100 nanoseconds. 3-5 bytes
Datetimeoffset Same as datetime2, plus time zone offset. 8-10 bytes
Timestamp Store a unique number. This number is updated every time a row is created or modified. The timestamp is based on the internal clock and does not correspond to the actual time. Each table can have only one timestamp variable.  
Other data types:
Data Type Description
SQL _variant Stores up to 8,000 bytes of data of different data types, except text, ntext, and timestamp.
Uniqueidentifier Stores the GLobal IDEntifier (GUID ).
Xml Store XML formatted data. 2 GB at most.
Cursor Stores references to pointers used for database operations.
Table Store the result set for later processing.

What are the data types in SQL?

It depends on which database you are using, such as SQL server and Oracle. Common examples include:
Integer, single precision, double precision, variable length characters, fixed length characters, long type, date ......

SQL data types

I. Integer Data Type

Integer data is one of the most common data types.

1. INT (INTEGER)

INT (or INTEGER) Data Type stores all positive and negative integers from the 31 Power (-2,147,483,648) of-2 to the 31 Power-1 (2,147,483,647) of 2. Data of each INT type is stored in four bytes. One digit indicates the positive and negative signs of the integer, And the other 31 digits indicate the length and size of the integer.

2. SMALLINT

SMALLINT stores all positive and negative integers from the 15th power (-32,768) of-2 to the 15th power-1 (32,767) of 2. Each SMALLINT data occupies 2 bytes of storage space. One digit indicates the positive and negative signs of the integer, and the other 15 digits indicate the length and size of the integer.

3. TINYINT

TINYINT data type stores all positive integers from 0 to 255. Each TINYINT data occupies 1 byte of storage space.

4. BIGINT

BIGINT data type stores all positive and negative integers from-2 ^ 63 (-9,223,372,036,854,775,807) to 2 ^ 63-1 (9,223,372,036,854,775,807. Each BIGINT data occupies 8 bytes of storage space.

Ii. Floating Point Data Type

The floating point data type is used to store decimal places. The data of floating point values is stored in SQL Server in the Round-robin (Round up) mode. When (and only if) the number to be rounded is a non-zero number, add 1 to the value in the lowest valid bit of the reserved number, and carry out the necessary carry. If a number is rounded up, its absolute value is not reduced. For example, round 3.14159265358979 by two or 12 digits, respectively. The result is 3.15 and 3.141592653590.

1. REAL Data Type

The REAL data type can be accurate to 7th decimal places in the range of-3.40E-38 to 3.40E + 38. Each REAL data occupies 4 bytes of storage space.

2. FLOAT

The FLOAT data type can be precise to 15th decimal places, ranging from-1.79E-308 to 1.79E + 308. Each FLOAT data occupies 8 bytes of storage space. FLOAT data can be written as FLOAT [n. N specifies the FLOAT data precision. N is an integer between 1 and 15. When n is 1 to 7, a REAL data type is defined. The system stores it in four bytes. When n is 8 to 15, the system considers it a FLOAT type and stores it in 8 bytes.

3. DECIMAL

The DECIMAL data type can provide the actual storage space required by decimals, but it also has certain limitations, you can use 2 to 17 bytes to store values between the power-38 and the power-1 from-10 to the power-1 from-10. It can be written as DECIMAL [p [s]. p and s determine the exact ratio and number. P indicates the total number of digits (excluding the decimal point) of the value that can be stored. The default value is 18. s indicates the number of digits after the decimal point. The default value is 0. For example, decimal (15 5) indicates a total of 15 digits, with an integer of 10 digits and a decimal of 5 digits. The 4-3 table lists the relationships between the number of bytes required for each precision.

4. NUMERIC

The NUMERIC data type is exactly the same as the DECIMAL data type.
Note: To work with front-end development tools, SQL Server supports a maximum of 28 data precision by default.

Iii. binary data type

1. BINARY

The BINARY data type is used to store BINARY data. It is defined as BINARY (n), and n indicates the length of the data. The value ranges from 1 to... the remaining full text>

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.