sqlserver type value range

SQL SERVER data types

A data type is an attribute of data that represents the type of information the data represents. Any computer language defines its own data types. Of course, different programming languages ​​have different characteristics.

SQL Server provides 25 data types:

Binary [(n)]、Varbinary [(n)]、Char[(n)]、Varchar[(n)]、Nchar[(n)]、Nvarchar[(n)]、Datetime、Smalldatetime、Decimal[(p[,s])]、Numeric[(p[,s])]、Float[(n)]、Real、Int、Smallint、Tinyint、Money、Smallmoney、Bit、Cursor、Sysname、Timestamp、Uniqueidentifier、Text、Image、Ntext

(1) Binary data type

Binary data includes Binary, Varbinary, and Image.  

Binary data types can be either fixed-length (Binary) or variable-length. Binary[(n)] is n-bit fixed binary data. Among them, the value range of n is from 1 to 8000. Its storage size is n+4 bytes.

Varbinary[(n)] is n-bit variable-length binary data. Among them, the value range of n is from 1 to 8000. Its storage size is n+4 bytes, not n bytes.

The data stored in the Image data type is stored as a bit string that is not interpreted by SQL Server and must be interpreted by the application. For example, applications can use the BMP, TIEF, GIF, and JPEG formats to store data in the Image data type.

(2) Character data type

Types of character data include Char, Varchar and Text. Character data is data composed of any combination of letters, symbols, and numbers.  

Varchar is variable-length character data whose length does not exceed 8KB.

Char is fixed-length character data, and its length is at most 8KB.

The Text data type stores more than 8KB of ASCII data. For example, because Html documents are all ASCII characters and typically exceed 8KB in length, these documents can be stored in SQL Server as Text data type.

(3) Unicode data type

Unicode data types include Nchar, Nvarchar and Ntext. In Microsoft SQL Server, traditional non-Unicode data types allow the use of characters defined by a specific character set. During SQL Server installation, a character set is allowed to be selected. Using the Unicode data type, any character defined by the Unicode standard can be stored in the column. In the Unicode standard, all characters defined in various character sets are included. Using Unicode data types takes up twice as much capacity as using non-Unicode data types. In SQL Server, Unicode data is stored in Nchar, Nvarchar, and Ntext data types. Columns stored using this character type can store characters from multiple character sets.

When the length of the column changes, the Nvarchar character type should be used, which can store up to 4000 characters.

When the length of the column is fixed, the Nchar character type should be used, and again, a maximum of 4000 characters can be stored at this time.

When using the Ntext data type, the column can store more than 4000 characters.

(4) Date and time data types

Date and time data types include Datetime and Smalldatetime  

Date and time data types consist of valid dates and times. For example, valid date and time data includes "4/01/98 12:15:00:00:00 PM" and "1:28:29:15:01AM 8/17/98". The former data type is date before and time after. The latter data type is time before and date after.

In Microsoft SQL Server, when the date and time data types include Datetime and Smalldatetime, the stored date range starts from January 1, 1753 and ends on December 31, 9999 (each value requires 8 storage bytes).

When using the Smalldatetime data type, the stored date range starts on January 1, 1900 and ends on December 31, 2079 (each value requires 4 bytes of storage). The format of the date can be set.

(5) Digital data type

Numeric data contains only numbers. Numeric data types include positive and negative numbers, decimals (floating point), and integers  

Integers consist of positive and negative integers, such as 39, 25, 0-2, and 33967.

In Micrsoft SQL Server, the data types for integer storage are Int, Smallint and Tinyint.

The range of data stored by the Int data type is larger than the range of data stored by the Smallint data type, and the range of data stored by the Smallint data type is greater than the range of data stored by the Tinyint data type. The range of data stored using the Int data dog is from -2147483648 to 2147 483647 (each value requires 4 bytes of storage).

When using the Smallint data type, the range of stored data is from -32768 to 32767 (each value requires 2 bytes of storage space).

When using the Tinyint data type, the range of stored data is from 0 to 255 (each value requires 1 byte of storage space).  

The data types for exact decimal data in SQL Server are Decimal and Numeric. The storage space occupied by such data is determined according to the number of digits after the decimal of the data.

In SQL Server, the data types for approximate decimal data are Float and Real. For example, a fraction of one third is written as .3333333, which is accurate when using approximate data types. Therefore, the data retrieved from the system may not be exactly the same as the data stored in the column.

(6) Currency data indicating positive or negative currency quantities 

In Microsoft SQL Server, the data types for currency data are Money and Smallmoney

The Money data type requires 8 bytes of storage, and the Smallmoney data type requires 4 bytes of storage.

(7) Special data types

Special data types include data types not mentioned earlier.

There are three special data types, namely Timestamp, Bit and Uniqueidentifier.  

Timestamp is used to represent the sequence of SQL Server activities in binary format. Timestamp data has nothing to do with insert data or date and time.  

Bit consists of 1 or 0. When representing true or false, ON or OFF, use the Bit data type.

Uniqueidentifier consists of a 16-byte hexadecimal number that represents a globally unique. Uniqueidentifier is very useful when the records of the table are required to be unique.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326481628&siteId=291194637