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
备注
- 有关详细信息,请参阅跨数据库和跨群集查询。For more information, see cross-database and cross-cluster queries.
- 若要访问远程群集和远程数据库,请参阅 cluster() 范围函数。For accessing remote cluster and remote database, see cluster() scope function.
语法Syntax
database(
stringConstant)
database(
stringConstant)
参数Arguments
- stringConstant:被引用数据库的名称。stringConstant: Name of the database that is referenced. 标识的数据库可以是
DatabaseName
或PrettyName
。Database identified can be eitherDatabaseName
orPrettyName
. 在执行查询之前,参数必须是常量,即不能来自子查询求值。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