database()
Learn how to use the database() function to change the reference of the query to a specific database.
Changes the reference of the query to a specific database within the cluster scope.
Changes the reference of the query to a specific database within the Eventhouse scope.
``
Syntax
database(databaseName)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| databaseName | string | The name of the database to reference. The databaseName can be either the DatabaseName or PrettyName. The argument must be a constant value and can’t come from a subquery evaluation. |
Examples
Use database() to access table of other database
database('Samples').StormEvents | count
Output
| Count |
|---|
| 59066 |
Use database() inside let statements
The query above can be rewritten as a query-defined function (let statement) that
receives a parameter dbName - which is passed into the database() function.
let foo = (dbName:string)
{
database(dbName).StormEvents | count
};
foo('help')
Output
| Count |
|---|
| 59066 |
Use database() inside stored functions
The same query as above can be rewritten to be used in a function that
receives a parameter dbName - which is passed into the database() function.
.create function foo(dbName:string)
{
database(dbName).StormEvents | count
};
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.