将JSON数据导入SQL Server

This article explores the process of JSON data import in the SQL Server table using T-SQL and SSIS.

本文探讨了使用T-SQL和SSIS在SQL Server表中导入JSON数据的过程。

介绍 (Introduction)

Java Script Object Notation is an accessible data exchange format. Many applications support JSON format data nowadays. We can use JSON data for unstructured data such as log files and NoSQL databases. SQL Server also supports JSON format data import and export for exchanging data with different data sources and applications.

Java脚本对象表示法是一种可访问的数据交换格式。 如今,许多应用程序都支持JSON格式数据。 我们可以将JSON数据用于非结构化数据,例如日志文件和NoSQL数据库。 SQL Server还支持JSON格式的数据导入和导出,以与不同的数据源和应用程序交换数据。

We can use SQL Server FOR XML PATH or FOR XML Auto clause in the SQL Server query, and it retrieves the results into the JSON format. We have explored this in the article How to import/export JSON data using SQL Server 2016.

我们可以在SQL Server查询中使用SQL Server的FOR XML PATH或FOR XML Auto子句,它将结果转换为JSON格式。 我们已在文章如何使用SQL Server 2016导入/导出JSON数据中对此进行了探讨

In the following image, we can see built-in functions for converting text into JSON and vice-versa:

在下图中,我们可以看到用于将文本转换为JSON(反之亦然)的内置函数:

JSON Data format SQL Server

Azure Data Studio JSON格式输出 (Azure Data Studio JSON format output)

We can also save results in JSON format without specifying any parameter in Azure Data Studio. Let’s execute a query in the AdventureWorks sample database in Azure Data Studio:

我们还可以将结果保存为JSON格式,而无需在Azure Data Studio中指定任何参数。 让我们在Azure Data Studio的AdventureWorks示例数据库中执行查询:

SELECT TOP (10) [FirstName], 
                [MiddleName], 
                [LastName], 
                [JobTitle], 
                [PhoneNumber], 
                [PhoneNumberType], 
                [EmailAddress], 
                [EmailPromotion]
FROM [AdventureWorks].[HumanResources].[vEmployee];

We get the output in the tabular format as shown below:

我们以表格格式获得输出,如下所示:

Azure Data Studio Output formats

In the above screenshot, we have following output formats:

在上面的屏幕截图中,我们具有以下输出格式:

  • Save as CSV

    另存为CSV
  • Save as Excel

    另存为Excel
  • Save as JSON

    另存为JSON
  • Save as XML

    另存为XML
  • Chart

    图表
  • Visualizer

    可视化器

Save as JSON option

Click on Save as JSON, and it asks you for specifying the directory and file name for JSON file:

单击另存为JSON ,它要求您指定JSON文件的目录和文件名:

Specify directory and file name

Click on Save, and it shows the JSON format output:

单击Save ,它显示JSON格式输出:

  • 4
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值