Query layers are SQL queries stored in the map in ArcMap. Query layers allow you to access spatial and nonspatial tables and views in databases. Because query layers access the database directly using SQL, the data does not have to be part of an enterprise geodatabase, but you can define query layers for enterprise geodatabase tables and feature classes if you need to. For example, you may not have permissions in the database to create a view, but you want to limit what data from a feature class shows up in your map. You can create a query layer in the map that selects only certain fields or values from the feature class.
You create query layers by defining an SQL query. The query runs against the tables and views in the database you specify, and the result set is added to the map as a layer if your query includes a spatial column or a stand-alone table if it does not.
The SQL query that defines a query layer is a static SQL statement that is executed inside the database every time the layer is displayed or used in the map. This allows the latest information to be visible without making a copy or snapshot of the data. This is especially useful when working with dynamic information that is frequently changing.
Keep the following in mind when working with query layers:
- Query layers are supported for specific database management systems.
- To use query layers in a map, either drag a table from a database onto the map or define a query against the tables and views in a database or enterprise geodatabase using the New Query Layer dialog box.
- When you add or drag a database table to your map, ArcMap automatically creates a query layer that selects all fields and rows from the table. You can change what is available in the map by modifying the query layer definition from the layer's properties.
- Alternatively, you can define the query layer before data is added to the map. You must use this method to define a query layer for data in an enterprise geodatabase.
- Query layers behave in the same way as other feature layers or stand-alone tables in a map; you can use them to display data, use them as input to a geoprocessing tool, or access them programmatically using developer APIs.
- Query layers are read only when accessed directly from a database connection.
- To edit database tables that are accessed as a query layer, share as a web feature layer and access from your portal. Note that the query layer cannot contain virtual columns, where clauses, or joins.
- After you create a query layer, you can save it as a layer file (.lyr) or use it to create a layer package (.lpk). This allows you to share query layers with other applications, map documents, and people.
- You can export the data from a query layer to another database or enterprise geodatabase.