Query layers are SQL queries stored in maps in ArcGIS Pro projects. 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 might 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. However, there are many situations where parts of SQL statements are not known in advance. For example, to display aggregated rainfall in a region, you may not know beforehand whether to aggregate the rainfall station values by day, week, or month. Parameters in query layers can help make components of SQL statements dynamic.
Keep the following in mind when working with query layers:
- Query layers are supported for specific database management systems.
- When you drag a table from a database in your project onto a map, ArcGIS Pro 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; they can be used to display data, used as input to a geoprocessing tool, or accessed programmatically using developer APIs.
- You can export the data from a query layer to another database or enterprise geodatabase.