Alias statement

Switch services using the Version drop-down list. Learn more about navigation.
Applies to: ✅ Azure Data Explorer ✅ Azure Monitor ✅ Microsoft Sentinel

Alias statements allow you to define an alias for a database, which can be used in the same query.

The alias statement is useful as a shorthand name for a database so it can be referenced using that alias in the same query.

Syntax

alias database DatabaseAliasName = cluster("QueryURI").database("DatabaseName")

Learn more about syntax conventions.

Parameters

Name Type Required Description
DatabaseAliasName string ✔️ An existing name or new database alias name. You can escape the name with brackets. For example, ["Name with spaces"].
QueryURI string ✔️ The URI that can be used to run queries or management commands.
DatabaseName string ✔️ The name of the database to give an alias.

Note

  • To get your Query URI, in the Azure portal, go to your cluster's overview page, and then copy the URI.
  • The mapped Query and the mapped database-name must appear inside double-quotes(") or single-quotes(').

Important

Alias statements are supported only within the scope of a single query.

Alias statements aren’t supported in function definitions, including user-defined functions, stored functions, or reusable query artifacts.

Aliases must be defined and referenced within the same query and can’t be persisted or reused across queries.

Examples

The examples in this article use publicly available tables in the help cluster, such as the StormEvents table in the Samples database.

First, count the number of records in that table.

StormEvents
| count

Output

Count
59066

Then, give an alias to the Samples database and use that name to check the record count of the StormEvents table.

alias database samplesAlias = cluster("https://help.chinaeast2.kusto.chinacloudapi.cn").database("Samples");
database("samplesAlias").StormEvents | count

Output

Count
59066

Create an alias name that contains spaces using the bracket syntax.

alias database ["Samples Database Alias"] = cluster("https://help.chinaeast2.kusto.chinacloudapi.cn").database("Samples");
database("Samples Database Alias").StormEvents | count

Output

Count
59066