【发布时间】:2020-04-23 05:32:21
【问题描述】:
我对 SQL 不是很熟悉。
我的 SQL Server 数据库中有一个名为 Product 的表
CREATE TABLE [dbo].[Product] (
[Age] INT NULL,
[Name] NVARCHAR (50) NULL,
[Id] NVARCHAR (50) NULL,
[Price] DECIMAL (18) NULL,
[ImageUrl] NVARCHAR (50) NULL,
[Snippet] NVARCHAR (50) NULL
)
我有一个 JSON 文件(位于 D:\demo\myjson.json),其中存储了我的所有产品信息,例如:
[
{
"Age": 0,
"Id": "motorola-xoom-with-wi-fi",
"ImageUrl": "static/imgs/phones/motorola-xoom-with-wi-fi.0.jpg",
"Name": "Motorola XOOM\u2122 with Wi-Fi",
"Price":5000,
"Snippet": "The Next, Next Generation\r\n\r\nExperience the future with Motorola XOOM with Wi-Fi, the world's first tablet powered by Android 3.0 (Honeycomb)."
},
{
"Age": 1,
"Id": "motorola-xoom",
"ImageUrl": "static/imgs/phones/motorola-xoom.0.jpg",
"Name": "MOTOROLA XOOM\u2122",
"Price":5000,
"Snippet": "The Next, Next Generation\n\nExperience the future with MOTOROLA XOOM, the world's first tablet powered by Android 3.0 (Honeycomb)."
}
]
如何编写 sql 来获取此文件并将数据导入我的 Product 表而不是手动执行此操作?
我正在使用 SQL Server 2016 和 SSMS。
【问题讨论】:
-
我建议通过查看您的数据将 [Snippet] 列从 NVARCHAR(50) 更改为 NVARCHAR(MAX)。
标签: sql json sql-server sql-server-2016