SQL SERVER – QUOTED_IDENTIFIER ON/OFF Explanation and Example – Question on Real World Usage

This is a follow up blog post of SQL SERVER – QUOTED_IDENTIFIER ON/OFF and ANSI_NULL ON/OFF Explanation. I wrote that blog six years ago and I had plans that I will write a follow up blog post of the same. Today, when I was going over my to-do list and I was surprised that I had an item there which was six years old and I never got to do that.

In the earlier blog post I wrote about exploitation of the Quoted Identifier and ANSI Null. In this blog post we will see a quick example of Quoted Identifier. However, before we continue this blog post, let us see a refresh what both of Quoted Identifider do.


This option specifies the setting for use of double quotes. When this is on, double quotation mark is used as part of the SQL Server identifier (object name). This can be useful in situations in which identifiers are also SQL Server reserved words.

In simple words when we have QUOTED IDENTIFIER ON, anything which is wrapped in double quotes becomes an object.


-- The following will work
-- The following will throw an error about Incorrect syntax near 'Test2'.

This feature is particularly helpful when we are working with reserved keywords in SQL Server. For example if you have to create a database with the name VARCHAR or INT or DATABASE you may want to put double quotes around your database name and turn on quoted identifiers to create a database with the such name. Personally, I do not think so anybody will ever create a database with the reserve keywords intentionally, as it will just lead to confusion.

Here is another example to give you further clarity about how Quoted Idenifier setting works with SELECT statement.

-- The following will throw an error about Invalid column name 'Column'.
SELECT "Column"
-- The following will work
SELECT "Column"


I always use the following method to create database as it works irrespective of what is the quoted identifier’s status. It always creates objects with my desire name whenever I would like to create.


I believe the future of the quoted identifier on or off is useful in the real world when we have script generated from another database where this setting was ON and we have to now execute the same script again in our environment again.

Question to you -

I personally have never used this feature as I mentioned earlier. I believe this feature is there to support the scripts which are generated in another SQL Database or generate the script for other database. Do you have a real world scenario where we need to turn on or off Quoted Identifiers.

Click to Download Scripts

Reference: Pinal Dave (http://blog.sqlauthority.com)

About these ads

3 thoughts on “SQL SERVER – QUOTED_IDENTIFIER ON/OFF Explanation and Example – Question on Real World Usage

  1. Yes, I have real word scenario. The situation is like this – We have to add a computed column and index on that. To work this, you must have to have the quoted identifier on.
    Also if your procedures that are going to do insert/updare on that table and those prorcedures are created with quoted identifier OFF then so you must have to re-create procedures with the quoted identifier ON other wise it will lead to below error.

    Msg 1934, Level 16, State 1, Procedure XXXX
    INSERT failed because the following SET options have incorrect settings: ‘QUOTED_IDENTIFIER’. Verify that SET options are correct for use with indexed views and/or indexes on computed columns and/or filtered indexes and/or query notifications and/or XML data type methods and/or spatial index operations.

  2. Yes, I have a real world scenario as well. I got the same error as mentioned by vinayak.
    The Query was working fine with a cursor to retrieve rows and send email feature in it. But when I used the same query in SQLJOB, I got this error.

  3. Here is the code snippet
    SET @tableHTML =
    N’ANCDS Application’ +
    N’Following Bulletins need attention’ +
    N’Click Dashboard to open the application or individual links below to take quick action. ‘+
    N” +
    N’Bulletin NumberBulletin Name’ +
    td = NavigateURL , ”
    FROM [dbo].[vwDailySummary]
    WHERE Status = 2 AND EmailId = @EmailID
    FOR XML PATH(‘tr’), TYPE
    ).value(‘.’,’NVARCHAR(MAX)’) AS NVARCHAR(MAX) ) +
    N” ;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s