SQLServer Data Type

Source: Internet
Author: User
Reprinted: the data type is an attribute of the data, and is the type of information represented by the data. Any language has its own data types. SQLServer provides 25 inherent data types. SQL Server Data Type list · Binary [(n)] · Varbinary [(n)] · Char [(n)] · Varchar [(n)] · Nchar [(n)] · Nv

Reprinted: the data type is an attribute of the data, and is the type of information represented by the data. Any language has its own data types. SQL Server provides 25 inherent data types. SQL Server Data Type list · Binary [(n)] · Varbinary [(n)] · Char [(n)] · Varchar [(n)] · Nchar [(n)] · Nv

Reprinted:

A data type is a type of data attribute and a type of information represented by data. Any language has its own data types. SQL Server provides 25 inherent data types.

SQL Server Data Type list
· 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 is represented by a hexadecimal number. binary, varbinary, and image data types can be used for storage.
· Binary data types with a fixed length (up to 8 K.

Binary [(n)]
A fixed length of n Bytes of binary data. N must be from 1 to 8,000. The storage space is n + 4 bytes.

· Varbinary binary data type with a variable length (up to 8 K.

Varbinary [(n)]
N Bytes of variable-length binary data. N must be from 1 to 8,000. The size of the bucket is the length of the actual input data + 4
Not n Bytes. The input data length may be 0 bytes. Varbinary's
The synonym is binary varying.

· Image is used to store binary data with a variable length of more than 8 KB.
Unless the data length exceeds 8 KB, The varbinary type is generally used to store binary data. It is generally used to store Microsoft Word documents, Microsoft Excel workbooks, images containing bitmap, GIF files, and JPEG files.
The data stored in the Image data type is stored as a bit string, which is not explained by SQL Server and must be explained by the application. For example, an application can store data in the Image data type in BMP, TIEF, GIF, and JPEG formats.

2. character data type
Character data consists of letters, symbols, and numbers. Char, varchar, and text data types are used for storage.
· Char character data type with a fixed length (up to 8 KB.

Char [(n)]
Character data with a fixed length of n Bytes and is not Unicode. N must be between 1 and 8,000
Between. The storage size is n Bytes. The synonym for char in the SQL-92 is character.

· Varchar variable length (up to 8 KB) character data type.

Varchar [(n)]
Variable-length and non-Unicode character data with a length of n Bytes. N must be between 1 and 8,000
Between. The storage size is the actual length of the input data bytes, rather than n Bytes. Data words entered
The length can be zero. The synonym for varchar in the SQL-92 is char varying or character varying.

· Columns of the text data type can be used to store ASCII characters larger than 8 KB.
For example, because HTML documents are composed of ASCII characters and generally longer than 8 KB, they should be stored in the text column on SQL Server before being viewed in a browser.

3. Unicode Data Type
The Unicode data type allows a column to store any character defined by the Unicode standard, including all characters defined by different character sets. Unicode data is stored using the nchar, varchar, and ntext Data Types in SQL Server.
· Unicode data type with a fixed nchar length (up to 4000 Unicode characters.

Nchar (n) contains Unicode characters of a fixed length of n characters. The value of n must be between 1 and 4,000. Storage size: n characters
Double the number of segments. The synonyms of nchar in the SQL-92 are national char and national character.

· Nvarchar (varchar) is a variable-length Unicode data type.

Nvarchar (n) contains variable-length Unicode characters of n characters. The value of n must be between 1 and 4,000.
The storage size of bytes is twice the number of input characters. The length of the input data can be zero. The synonym for nvarchar in the SQL-92 is national char varying and national character varying.

· Ntext is used when any item in the column contains more than 4000 Unicode characters.

4. Date and Time Data Types
Date and Time data are composed of valid date or time. For example, the valid date and time data include "4/01/98 12: 15: 00: 00: 00 PM" and "1: 28: 29: 15: 01 AM 8/17/98 ". In Microsoft SQL Server 2000, date and time data are stored in the datetime and smalldatetime data types.
· Datetime
Data Type storage starts from January 1.
Each value requires 8 bytes of storage space.

· Smalldatetime
The data type storage period ranges from January 1, January 1-20, 1900 to January 1, June 6.
Each value requires a storage space of 4 bytes.

· Set the date
The command format is as follows:
Set DateFormat {format | @ format _ var |
Where, format | @ format_var is the date order. Valid parameters include MDY, DMY, YMD,
YDM, MYD, and DYM. By default, the date format is MDY.

5. Digital Data Type
Numeric data only contains numbers. Numeric data includes positive, negative, decimal, fractional, and integer.
· Integer Data
Integer Data is composed of negative integers or positive integers, such as-15, 0, 5, and 2509. In Microsoft SQL Server
In 2000, integer data is stored in bigint, int, smallint, and tinyint data types. Bigint Data Type
Type can store a wider range of numbers than int data types. Int data type is more storage range than smallint Data Type
The value range of smallint is larger than that of tinyint.

Bigint storage range from-2 ^ 63 (-9223372036854775808) to 2 ^ 63-1 (9223372036854775807)
Number. The storage size is 8 bytes.

The int storage range is-2,147,483,648 to 2,147,483,647 (each value requires 4 bytes of storage space ).

The smallint storage range is only-32,768 to 32,767 (each value requires 2 bytes of storage space ).

Tinyint can only store numbers ranging from 0 to 255 (each value requires a storage space of 1 byte ).

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.