After you add a query layer to the map, you can alter the SQL query and other properties of the layer. To do this, open the Edit Query Layer dialog box from the Layer Properties dialog box.
When you add a spatial table stored in a database to the map, it creates a query layer with default properties as determined by the first row in the table. These properties may not be ideal, however. For example, a spatial table can have multiple geometry types for a single spatial attribute. A spatial table containing a collection of cities can be modeled in the database as both a point and a polygon geometry type. Feature layers in ArcGIS can only have a single geometry type, so the first row in the table provides the default geometry type property. In this example, if the first row in the spatial table containing cities data returns a point geometry, the cities query layer will only display point features. If you would prefer to view the polygon features that are stored in the cities table, modify the query layer properties on the Edit Query Layer dialog box and change the geometry type to polygon.
Other properties, such as a query layer's dimensionality, spatial reference, SRID, and unique identifier field, are also determined by the first row returned from the spatial table. Similar to the geometry type, you can access these properties in the advanced options pane of the Edit Query Layer dialog box and modify them.
When you change the dimensionality of the query layer, the geometry field value of the displayed features are modified to match that change.
For example, for a layer defined with x-, y-, z-, and m-dimensionality in the database, if you edit the query layer and uncheck the Coordinates include M values and Coordinates include Z values options in the advanced options, all the features in the layer will display only the x- and y-values. Alternatively, if you edit the query layer and check the Coordinates include M values and Coordinates include Z values options, all the features will display x-, y-, z-, and m-values. If you check those options and a feature does not contain a z- or m-value in the database, those values will appear as null in the query layer.
When you change the spatial reference or SRID of the query layer in the advanced options of the Edit Query Layer dialog box, the features displayed in ArcMap are filtered based on that spatial reference or SRID value.
Follow these steps to alter the definition and properties of a query layer:
- In the table of contents, right-click the query layer whose query you want to modify.
- Click Properties to open the Layer Properties dialog box.
- Click the Source tab.
- Click Change Query.
The Edit Query Layer dialog box appears.
- If you want to change the SQL statement that defines the query layer, modify the query in the Query text box.
See Building a query expression for more information on writing an SQL query in ArcGIS.
- Click Validate to make sure that the query expression is correct.
- If you want to modify the unique identifier or any of the spatial properties of the query layer, such as its dimensionality, SRID, spatial reference, or geometry type, click the Show advanced options check box and click Next.
See Create a query layer for more information on advanced options.
- Click Finish to close the dialog box.
- On the Layer Properties dialog box, click OK to display the new result set for the query layer and close the dialog box.