Set ansi_nulls on and set quoted_identifier on, set ansi_padding

Source: Internet
Author: User
Tags odbc connection ole

Set quoted_identifier on
Go
What does that mean?

 

Syntax
Set quoted_identifier {on | off}

Note
When set quoted_identifier is on, the identifiers can be separated by double quotation marks, and the text must be separated by single quotation marks. When setquoted_identifier is off, the identifier cannot be enclosed in quotation marks and must comply with all the rules of the transact-SQL identifier. For more information, see use identifiers. The text can be separated by single or double quotation marks.

When set quoted_identifier is on, all strings separated by double quotation marks are interpreted as object identifiers. Therefore, the quoted identifiers do not have to comply with the rules of transact-SQL identifiers. They can be reserved keywords and contain characters that are generally not allowed in the transact-SQL identifier. Character string expressions cannot be separated by double quotation marks, but must be enclosed by single quotation marks. If single quotes (') are part of a text string, they can be expressed by two single quotes. When a reserved keyword is used for the object name in the database, setquoted_identifier must be on.

When set quoted_identifier is off (default), the text strings in the expression can be separated by single quotes or double quotation marks. If the text string is separated by double quotation marks, it can contain embedded single quotation marks, such as ellipsis.

When you create or operate an index on a calculated column or index view, set quoted_identifier must be on. If setquoted_identifier is off, the CREATE, update, insert, and delete statements on the table with an index on the calculation column or index view will fail. For more information about the set option settings required for the index view and index on the calculation column, see "considerations when using the set statement" in set ".

 

 

 

What does set ansi_nulls on mean?

The SQL-92 standard requires that the value be false when a null value is equal to (=) or not equal to (<>. When set ansi_nulls is on, even if column_name contains a null value, the SELECT statement using wherecolumn_name = NULL still returns zero rows. Even if column_name contains a non-null value, the SELECT statement using wherecolumn_name <> null still returns zero rows.
When set ansi_nulls is off, equal to (=) and not equal to (<>) Comparison operators do not comply with SQL-92 standards. Use the SELECT statement where wherecolumn_name = NULL to return rows containing null values in column_name. Use the SELECT statement of wherecolumn_name <> null to return rows that contain non-null values. In addition, use the SELECT statement where column_name <> xyz_value to return all rows that are neither xyz_value nor null.

Set ansi_padding

Controls the storage of column-to-column values smaller than the defined column size, and column-to-ColumnChar,Varchar,BinaryAnd
VarbinaryThe storage method of values with Trailing spaces in the data.

Syntax

Set ansi_padding {on | off}

Note

UseChar,Varchar,BinaryAnd
Varbinary
The column defined by the data type has a certain size.

This setting only affects the definition of the new column. After a column is created, Microsoft SQL Server sets the storage value based on the storage value when the column is created. The existing columns are not affected by future changes.

WarningWe recommend that you always set ansi_padding to on.

The following table shows that the inserted values containChar,Varchar,BinaryAnd
VarbinarySet ansi_padding setting for data-type columns.

Set Char (N) Not null or binary (N) Not null Char (N) Null or binary (N) Null Varchar (N) Or varbinary (N)
On Set the start value (includingCharTrailing spaces andBinaryColumn trailing zero) Fill in the column length. When set ansi_padding is onChar (N)Or
Binary (N)Not null.
Insert without croppingVarcharTrailing spaces of character values in the column. Insert without croppingVarbinary
The trailing zero of the binary value in the column. Do not fill the value in the column length.
Off Set the start value (includingCharTrailing spaces andBinaryColumn trailing zero) Fill in the column length. When set ansi_padding is offVarcharOr
Varbinary
Same rule.
Cropping and insertingVarcharTrailing spaces of character values in the column. Cropping and insertingVarbinary
The trailing zero of the binary value in the column.

DescriptionWhen filling,CharColumns are filled with spaces,Binary
The column is filled with zero. When cropping,CharThe trailing spaces of the column are trimmed,BinaryThe trailing zeros of a column are trimmed.

When you create or operate an index on a calculated column or index view, set ansi_padding must be on. For more information about the set option settings required for the index view and index on the calculation column, see
"Considerations when using the set statement" in set ".

The SQL Server ODBC driver and the Microsoft ole db provider for SQL Server automatically set ansi_padding to on when connecting. This can be configured in the ODBC data source, ODBC connection feature, or ole db connection attribute (they are set in the application before connection. For connections from DB-Library applications, ansi_padding is off by default.

Nchar,NvarcharAndNtextThe column always displays the set ansi_padding on behavior, regardless of the current setting of set ansi_padding.

When set ansi_defaults is on, set ansi_padding is enabled.

Set ansi_padding is set during execution or running, rather than during analysis.

Permission

Set ansi_padding Permissions are granted to all users by default.

Example

The following example shows how this setting affects each of these data types.

SET ANSI_PADDING ONGOPRINT 'Testing with ANSI_PADDING ON'GOCREATE TABLE t1 (charcol char(16) NULL, varcharcol varchar(16) NULL, varbinarycol varbinary(8))GOINSERT INTO t1 VALUES ('No blanks', 'No blanks', 0x00ee)INSERT INTO t1 VALUES ('Trailing blank ', 'Trailing blank ', 0x00ee00)SELECT 'CHAR'='>' + charcol + '<', 'VARCHAR'='>' + varcharcol + '<',   varbinarycolFROM t1GOSET ANSI_PADDING OFFGOPRINT 'Testing with ANSI_PADDING OFF'GOCREATE TABLE t2 (charcol char(16) NULL, varcharcol varchar(16) NULL, varbinarycol varbinary(8))GOINSERT INTO t2 VALUES ('No blanks', 'No blanks', 0x00ee)INSERT INTO t2 VALUES ('Trailing blank ', 'Trailing blank ', 0x00ee00)SELECT 'CHAR'='>' + charcol + '<', 'VARCHAR'='>' + varcharcol + '<',   varbinarycolFROM t2GODROP TABLE t1DROP TABLE t2GO

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.