I use Definition Queries a lot in my daily GIS life, but one of the many things I've found annoying about ArcMap is the inability to comment out Definition Queries. I'd like to have this option as sometimes I want to turn on/off the Definition Query or I want to have multiple Queries on a single Shapefile, but only one active at a time.

So far to get around this, I usually just have a notepad document in the background and copy and paste as necessary. But the ideal solution would be to use the definition query tab in the layer properties to replace this document. I might have multiple different queries on a layer, but all commented out.

As I understand, Definition Queries are written in SQL. To comment in SQL I believe you either start a line with: -- or encompass a statement in brackets: { }. I've tried both of these:


The last two statements return a SQL expression error and won't draw in ArcMap. I'm not looking for a programming solution, as that would just be too much work.

  • 2
    I don't have ArcGIS on this system to Check out, but does something like 'OR 1=1' or maybe even ObjectID>-1 work? – Devdatta Tengshe Jan 4 '13 at 16:01
  • @DevdattaTengshe that does work too pretty much comment out a query: "OBJECTID" <> -1 OR "DATA_AQUISITION" LIKE 'MISSING XSECTION' That's a great solution, but I am looking for something that seems more like an actual comment out. Something that can be done in every language of code, where you have multiple query options on different lines and all but one are commented out. If its not possible, so be it, but I believe it would be a great option to have. – Cody Brown Jan 4 '13 at 16:07

Just a guess, but the reason commenting it out doesn't work is probably because a definition query is just the WHERE clause part of a larger SQL statement built internally by ArcGIS whenever it needs to query the underlying database, for example to draw the layer. When you add the comment characters, ArcGIS still adds the WHERE clause and the underlying DB freaks because it's not valid SQL.

On the Query Builder dialog there are load and save buttons. Save creates a .exp file that you can then load back in with the Load button. It's a few more clicks than you are probably looking for but it's something.

  • That's true that it's just part of a larger statement. It's very possible that the DB freaks when we add a comment, but I know it is possible in other programs that use SQL to add a comment in the middle of a statement. The saving and loading of a .exp is something I was using before, but like you said it is a few clicks more than I am looking for. I also am trying to reduce the amount of code and files attached to each MXD I have and that would instead increase it. – Cody Brown Jan 4 '13 at 16:17
  • 2
    SELECT * FROM table WHERE is not valid SQL is what I was getting at. There has to be something following the WHERE keyword, or the WHERE keyword needs to not be there at all. ArcGIS probably adds WHERE if there is anything at all in the Definition Query. – blah238 Jan 4 '13 at 16:20
  • I tried SELECT * FROM table WHERE "OBJECTID" <> -1 --"DATA_AQUISITION" LIKE 'MISSING XSECTION' and SELECT * FROM table WHERE "OBJECTID" <> -1 {"DATA_AQUISITION" LIKE 'MISSING XSECTION'} Both result in the same errors. It has something following the WHERE, but still can't handle the comments. – Cody Brown Jan 4 '13 at 16:22
  • 1
    Huh. Well whatever the reason, clearly the commenting approach won't work. – blah238 Jan 4 '13 at 18:13
  • 4
    Actually, C-style commenting syntax looks like it works. Try this for example: 1 = 1 /*"DATA_AQUISITION" LIKE 'MISSING XSECTION'*/. Worked for me on Oracle. The 1 = 1 part is needed, using just the comment does not work (Missing Expression error). – blah238 Jan 4 '13 at 18:30

The block comment /../ seems to work as long as you have something in your definition query. If you comment everything out, you need to put a 1=1 before your commented out lines


All commented out:

  and ASSIGNMENT_STATUS <> 'Closed' 
  and DEVICE_TYPE = 'device'     
  and ASSIGNED_TO = 'somebody'    

1 uncommented, 2 commented out:

  and DEVICE_TYPE = 'device'     
  and ASSIGNED_TO = 'somebody'    

2 uncommented, 1 commented out:

DEVICE_TYPE = 'device'
  and ASSIGNED_TO = 'somebody'    

Just move the "/" and "/" around.


XTools pro, a non-ESRI add-on has a feature that enables to toggle a definition querry on/off on a layer. Very useful.

You can also copy/paste your defintion query in the Layer properties "General" tab. There is a window there for "Description" that is often unused. I often copy/paste my definition queries in there when I need to turn them off. There are saved in the document

  • Hmm sounds good, but does XTools cost money or is it a nice free add-on? – Cody Brown May 29 '15 at 15:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.