使用SQL Server仿真运行 KQL 查询和存储函数 您所在的位置:网站首页 command函数如何使用 使用SQL Server仿真运行 KQL 查询和存储函数

使用SQL Server仿真运行 KQL 查询和存储函数

#使用SQL Server仿真运行 KQL 查询和存储函数| 来源: 网络整理| 查看: 265

你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。

使用SQL Server仿真运行 KQL 查询和存储的函数 项目 03/09/2023

Azure 数据资源管理器提供表格格式数据流 (TDS) 终结点,使你能够以类似于在 SQL Server 中查询数据的方式查询数据。 本文介绍如何从 SQL 兼容客户端运行存储的函数和Kusto 查询语言 (KQL) 查询。

有关详细信息,请参阅 Azure 数据资源管理器 中的SQL Server仿真概述。

运行 KQL 查询

SQL 存储过程 sp_execute_kql 可用于运行 KQL 查询,包括参数化查询。 此过程与 sp_executesql 存储过程类似。

sp_execute_kql 的第一个参数是 KQL 查询,任何其他参数都被视为查询参数。 下面的示例说明如何使用 sp_execute_kql。

using (var connection = new SqlConnection(csb.ToString())) { await connection.OpenAsync(); using (var command = new SqlCommand("sp_execute_kql", connection)) { command.CommandType = CommandType.StoredProcedure; var query = new SqlParameter("@kql_query", SqlDbType.NVarChar); command.Parameters.Add(query); var parameter = new SqlParameter("mylimit", SqlDbType.Int); command.Parameters.Add(parameter); query.Value = "StormEvents | take myLimit"; parameter.Value = 3; using (var reader = await command.ExecuteReaderAsync()) { // Read the response. } } }

注意

通过 TDS 调用 sp_execute_kql 时,参数类型是由协议设置的,不需要声明。

调用存储的函数

可以创建和调用 SQL 存储过程等存储 函数 。 例如,如果具有下表中所述的存储函数,则可以调用它,如代码示例所示。

名称 parameters 正文 文件夹 DocString MyFunction (myLimit: long) {StormEvents | take myLimit} MyFolder 带参数的演示函数 using (var connection = new SqlConnection(csb.ToString())) { await connection.OpenAsync(); using (var command = new SqlCommand("kusto.MyFunction", connection)) { command.CommandType = CommandType.StoredProcedure; var parameter = new SqlParameter("mylimit", SqlDbType.Int); command.Parameters.Add(parameter); parameter.Value = 3; using (var reader = await command.ExecuteReaderAsync()) { // Read the response. } } }

注意

若要区分存储函数和模拟 SQL 系统存储过程,请使用对架构的显式引用调用存储函数 kusto 。 在此示例中,使用 kusto.Myfunction调用存储的函数。

后续步骤 使用 ODBC 连接 使用 JDBC 进行连接 从常见应用进行连接


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有