Redigera

Dela via


database()

Applies to: ✅ Microsoft FabricAzure Data Explorer

Changes the reference of the query to a specific database within the cluster scope.

Note

Changes the reference of the query to a specific database within the Eventhouse scope.

Note

  • For accessing remote cluster and remote database, see cluster() scope function.

``

Syntax

database(databaseName)

Learn more about syntax conventions.

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
};

Note

Such functions can be used only locally and not in the cross-cluster query.

Note

Such functions can be used only locally and not in the cross-Eventhouse query.