Chapter II single-Table query T-SQL language Basics (3)

Source: Internet
Author: User

Single-table query (3) 2.6 Processing character data

Query processing of character data, including: types, collations, operators and functions, and pattern matching.

2.6.1 data types

SQL Server supports two character data types----plain and Unicode characters. The common character data types include char and varchar,unicode character data types including nchar and nvarchar.

The difference between ordinary and Unicode characters: ordinary characters use one byte to hold each character, while Unicode characters require two bytes.

Note: When representing a normal character constant, simply use single quotation marks: ' This is a regular charactor string literal '; When a character constant representing a Unicode type needs to be preceded by a char n as the prefix, n ' This is a regular charactor string literal '

Any data type with a name that does not contain a VAR element is fixed-length (Char,nchar), and for such a type, SQL Server reserves a fixed amount of space in the row for the column as defined by the column, so the length of the column is not the actual number of characters in the string---- (This type of storage consumption is not optimal and may cost more when reading data.)

The data type that contains the Var element in the name is variable-length (Varchar,nvarchar), and SQL Server saves the data at the actual length of the string, plus two additional bytes to hold the offset value of the data.----( This type of update data may need to be extended to the row, causing the data to move beyond the scope of the current page. The efficiency of updating data with variable-length data types is reduced compared to fixed-length data types.

Note: When defining a variable-length data type, you can use the max specifier without specifying the maximum number of characters. (When you define a column with the max specifier, you can save a value directly to the inside of the row, with a limit of 8000 bytes, by default. Values larger than the upper limit will be used as large objects (Lob,large object), which are stored outside of the row).

2.6.2 sorting Rules (Collation)

Chapter II single-Table query T-SQL language Basics (3)

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.