SQL bit by bit: The Role of the SET QUOTED_IDENTIFIER OFF statement

Source: Internet
Author: User

Editor's note:SET QUOTED_IDENTIFIER

Make Microsoft®SQL Server™Follow the SQL-92 rules for the quotation mark separator and text string. The identifiers separated by double quotation marks can be keywords reserved by Transact-SQL, or can contain characters that are not allowed by the syntax rules of Transact-SQL identifiers.

First look at the following SQL statements

 
 
  1. SET QUOTED_IDENTIFIER ON 
  2. SELECT * FROM "USER"    WHERE a='netasp'   
  3.    
  4. SET QUOTED_IDENTIFIER ON 
  5. SELECT * FROM [USER] WHERE a='netasp'   
  6.  
  7. SET QUOTED_IDENTIFIER OFF 
  8. SELECT * FROM [USER]    WHERE a="netasp"   
  9.  
  10. SET QUOTED_IDENTIFIER OFF 
  11. SELECT * FROM [USER]    WHERE a= 'netasp' 

When you create a table named "USER" in the database, it is often troublesome because the USER is a keyword in SQL, but the preceding statements do not report an error. Another concept: the identifier is [] in SQL.

When the SET QUOTED_IDENTIFIER value is ON, the characters in double quotation marks are treated as database objects. That is to say, double quotation marks "" and identifiers [] have the same effect. They all indicate that the referenced characters are database objects. Single quotation marks (') indicate the boundary of a string.

When SET QUOTDE_IDENTIFIER OFF, double quotation marks are interpreted as string boundary, which is similar to single quotation marks. Double quotation marks cannot be used as identifiers, but can be used as character boundary. They have the same effect as single quotation marks.

A summary can be made: When SET QUOTED_IDENTIFIER ON "" is equivalent to [], it indicates the database object; when SET QUOTED_IDENTIFIER OFF "" is equivalent to '', it indicates the string boundary; the double quotation marks here are not combined by two single quotation marks. They are produced by shift +. Beginners may make such mistakes.
 

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.