Skip to main content

Add a SQL warehouse resource to a Databricks app

Add SQL warehouses as Databricks Apps resources to enable your app to connect to compute resources and run SQL queries.

Add a SQL warehouse resource

Before you can add a SQL warehouse as an app resource, check that you meet the prerequisites.

Follow the steps in this guide to add a resource. Select SQL warehouse as the resource type. Then:

  1. Choose a SQL warehouse from the available options in your workspace.
  2. Select the appropriate permission level for your app:
    • Can use: Grants the app permission to connect to the SQL warehouse and run queries. This is the minimum required permission for most applications.
    • Can manage: Grants the app permission to alter configuration, scaling, and other administrative settings. Only select this if your app specifically needs to administer the warehouse.
  3. (Optional) Specify a custom resource key, which is how you reference the SQL warehouse in your app configuration. The default key is sql-warehouse.

Environment variables

When you deploy an app with a SQL warehouse resource, Databricks exposes the warehouse ID through environment variables that you can reference using the valueFrom field.

For more information, see Access environment variables from resources.

Remove a SQL warehouse resource

When you remove a SQL warehouse resource from an app, the app's service principal loses access to the warehouse. The SQL warehouse itself remains unchanged and continues to be available for other users and applications that have appropriate permissions.

Best practices

Consider the following when you work with SQL warehouse resources:

  • Grant minimal permissions. Use Can use permissions unless your app specifically needs to perform administrative tasks on the warehouse.
  • SQL warehouses consume compute resources. Monitor your app's query patterns and warehouse utilization to optimize costs.
  • Implement retry logic and error handling in your app to manage potential connection issues or warehouse unavailability.
  • Select warehouse sizes that match your app's performance requirements and expected query loads.