database()(范围函数)database() (scope function)

将查询的引用更改为群集范围内的特定数据库。Changes the reference of the query to a specific database within the cluster scope.

database('Sample').StormEvents
cluster('help').database('Sample').StormEvents

备注

语法Syntax

database(stringConstant)database(stringConstant)

参数Arguments

  • stringConstant:被引用数据库的名称。stringConstant: Name of the database that is referenced. 标识的数据库可以是 DatabaseNamePrettyNameDatabase identified can be either DatabaseName or PrettyName. 在执行查询之前,参数必须是常量,即不能来自子查询求值。Argument has to be constant prior of query execution, i.e. cannot come from sub-query evaluation.

示例Examples

使用 database() 访问其他数据库的表Use database() to access table of other database

database('Samples').StormEvents | count
计数Count
5906659066

在 let 语句中使用 database()Use database() inside let statements

可以重写与上述查询相同的查询,以便使用可接收参数 dbName 的内联函数(let 语句)- 该参数会传递到 database() 函数中。The same query as above can be rewritten to use inline 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')
计数Count
5906659066

在函数中使用 database()Use database() inside functions

可以重写与上述查询相同的查询,以便在可接收参数 dbName 的函数中使用它 - 该参数会传递到 database() 函数中。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
};

备注

此类函数只能在本地使用,而不能在跨群集查询中使用。Such functions can be used only locally and not in the cross-cluster query.

Azure Monitor 不支持此功能This capability isn't supported in Azure Monitor