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(反之亦然)的内置函数:
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:
我们以表格格式获得输出,如下所示:
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 可视化器
Click on Save as JSON, and it asks you for specifying the directory and file name for JSON file:
单击另存为JSON ,它要求您指定JSON文件的目录和文件名:
Click on Save, and it shows the JSON format output:
单击Save ,它显示JSON格式输出: