---
title: CREATE CONNECTION
description: Create a foreign connection to a remote data system with CREATE CONNECTION in Databricks SQL and Databricks Runtime.
canonical_url: https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-create-connection
---

# CREATE CONNECTION

**Applies to:** ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks SQL ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks Runtime 13.3 LTS and above ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Unity Catalog only

This command creates a foreign connection (or server), which represents a remote data system of a specific type, using system specific options that provide the location of the remote system and authentication details.

Foreign connections enable [federated queries](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-federated-queries.md).

> [!NOTE]
>
> `CREATE CONNECTION` is for Lakehouse Federation (federated query) connections and HTTP connections. To create connections for managed ingestion pipelines in Lakeflow Connect, use the [Connections REST API](https://docs.databricks.com/api/workspace/connections/create) or the Databricks CLI (`databricks connections create`). See [Deployment](https://docs.databricks.com/aws/en/ingestion/lakeflow-connect/index.md#deployment).

> [!IMPORTANT]
>
> When you set connection options that carry a credential, such as a password or token, to keep them secure, provide the value using the [`secret`](https://docs.databricks.com/aws/en/sql/language-manual/functions/secret.md) function rather than entering the literal value directly in the `OPTIONS` clause. This lets you reference a secret stored in the [Databricks secret service](https://docs.databricks.com/aws/en/security/secrets/index.md) instead of including the credential value in your statement. See the [examples](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-create-connection.md#examples).

## Permissions

To create a connection, you must be a metastore admin or have the `CREATE CONNECTION` privilege on the metastore. If the connection references a service credential, you must also own the service credential or have `CREATE CONNECTION` on it. The referenced service credential must also be [accessible from the current workspace](https://docs.databricks.com/aws/en/connect/unity-catalog/cloud-services/service-credentials.md#workspace-binding).

## Syntax

```
CREATE CONNECTION [IF NOT EXISTS] connection_name
  TYPE connection_type
  OPTIONS ( option value [, ...] )
  [ COMMENT comment ]
```

For standards compliance you can also use `SERVER` instead of `CONNECTION`.

## Parameters

* **`connection_name`**

  A unique identifier of the connection at the Unity Catalog metastore level.

* **`connection_type`**

  Identifies the type of the connection and must be one of:

  * `DATABRICKS`
  * `HTTP` **Applies to:** Databricks SQL ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks Runtime 16.2 and above
  * `MYSQL`
  * `POSTGRESQL`
  * `REDSHIFT`
  * `SNOWFLAKE`
  * `SQLDW` (Synapse)
  * `SQLSERVER`

* **`OPTIONS`**

  Sets `connection_type` specific parameters needed to establish the connection.

  * **option**

    The property key. The key can consist of one or more [identifiers](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-identifiers.md) separated by a dot, or a `STRING` literal.

    Property keys must be unique and are case-sensitive.

  * **value**

    The value for the property. The value must be a `BOOLEAN`, `STRING`, `INTEGER`, or `DECIMAL` [constant expression](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-expression.md#constant-expression).

    For any option that carries a credential, such as a password or token, use the [`secret`](https://docs.databricks.com/aws/en/sql/language-manual/functions/secret.md) function instead of entering the value directly. For example, provide the `value` for `password` as `secret('secrets.r.us', 'postgresPassword')` rather than entering the literal password.

## Options by connection type

Each `connection_type` accepts its own set of `OPTIONS`. The following table lists the required options for each type. For optional settings, such as TLS and alternative authentication modes, and for setup steps, see the connection guide for each data source.

| Connection type | Required options                                  | Connection guide                                                                                                            |
| --------------- | ------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| `DATABRICKS`    | `host`, `httpPath`, `personalAccessToken`         | [Databricks-to-Databricks](https://docs.databricks.com/aws/en/query-federation/databricks.md)                               |
| `HTTP`          | `host`, `bearer_token`                            | [HTTP options](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-create-connection.md#http-options) |
| `MYSQL`         | `host`, `port`, `user`, `password`                | [MySQL](https://docs.databricks.com/aws/en/query-federation/mysql.md)                                                       |
| `POSTGRESQL`    | `host`, `port`, `user`, `password`                | [PostgreSQL](https://docs.databricks.com/aws/en/query-federation/postgresql.md)                                             |
| `REDSHIFT`      | `host`, `port`, `user`, `password`                | [Redshift](https://docs.databricks.com/aws/en/query-federation/redshift.md)                                                 |
| `SNOWFLAKE`     | `host`, `port`, `sfWarehouse`, `user`, `password` | [Snowflake](https://docs.databricks.com/aws/en/query-federation/snowflake-basic-auth.md)                                    |
| `SQLDW`         | `host`, `port`, `user`, `password`                | [Azure Synapse](https://docs.databricks.com/aws/en/query-federation/sqldw.md)                                               |
| `SQLSERVER`     | `host`, `port`, `user`, `password`                | [SQL Server](https://docs.databricks.com/aws/en/query-federation/sql-server.md)                                             |

> [!NOTE]
>
> Some connection types support additional authentication modes that use different options. For example, MySQL and PostgreSQL support AWS IAM authentication (with `aws_region` and `credential`), and Snowflake supports OAuth (with `client_id` and `client_secret`). See the connection guide for the data source.

## HTTP options

**Applies to:** Databricks SQL ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks Runtime 16.2 and above

The HTTP connection type supports the following option keys and values:

* `host`

  A `STRING` literal.
  Specifies the `host_name` for the external service.
  An exception will be thrown if the host path is a not a normalized URL.

* `bearer_token`

  The authentication token to be used when making the external service call.
  Provide the token using the [SECRET](https://docs.databricks.com/aws/en/sql/language-manual/functions/secret.md) function rather than as a `STRING` literal.
  For example, the value may comprise `secret('secrets.r.us', 'httpPassword')` as opposed to entering the literal token.

* `port`
  An optional `INTEGER` literal specifying the port. The default is `443`;

* `base_path`

  An optional `STRING` literal. The default is `/`.
  An exception is thrown if the path contains an empty string, or an incorrect path with spaces or special characters.

<a id="examples" />

## Examples

Provide credentials using the `secret` function, as shown in the following examples, rather than entering passwords or tokens directly.

```
-- Create a postgresql connection.
-- Provide the user and password using the secret function rather than
-- entering them directly.
> CREATE CONNECTION postgresql_connection
    TYPE POSTGRESQL
    OPTIONS (
       host '<hostname>',
       port '5432',
       user secret('secrets.r.us', 'postgresUser'),
       password secret('secrets.r.us', 'postgresPassword'));

-- Set up a connection to Slack.
-- Provide the bearer token using the secret function rather than a literal value.
> CREATE CONNECTION slack_conn
  TYPE HTTP
  OPTIONS (
    host 'https://slack.com',
    port '443',
    base_path '/api/',
    bearer_token secret('secrets.r.us', 'slackBearerToken')
  );

-- Request to the external service
> SELECT http_request(
    conn => 'slack_conn',
    method => 'POST',
    path => '/chat.postMessage',
    json => to_json(named_struct(
      'channel', channel,
      'text', text
    ))
    headers => map(
       'Accept', "application/vnd.github+json",
    )
  );
```

## Related articles

* [ALTER CONNECTION](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-alter-connection.md)
* [COMMENT ON CONNECTION](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-comment.md)
* [DESCRIBE CONNECTION](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-aux-describe-connection.md)
* [DROP CONNECTION](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-drop-connection.md)
* [Federated Queries](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-federated-queries.md)
* [INFORMATION\_SCHEMA.CONNECTIONS](https://docs.databricks.com/aws/en/sql/language-manual/information-schema/connections.md)
* [SHOW CONNECTIONS](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-aux-show-connections.md)
* [`http_request` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/http_request.md)
