我一直在尝试将 JSON 文件的内容导出到 SQL Server 表。但是,尽管 JSON 中存在多行,但输出 SQL 表仅包含 JSON 中的第一行。我正在使用的代码如下:
DROP TABLE IF EXISTS testingtable;
DECLARE @json VARCHAR(MAX) = '{ "_id" : "01001", "city" : "AGAWAM", "loc" : [ -72.622739, 42.070206 ], "pop" : 15338, "state" : "MA" },
{ "_id" : "01002", "city" : "CUSHMAN", "loc" : [ -72.51564999999999, 42.377017 ], "pop" : 36963, "state" : "MA" }';
SELECT * INTO testingtable FROM OPENJSON(@json) WITH (_id int, city varchar(20), loc float(50), pop int, state varchar(5)
)
SELECT * FROM testingtable
并且得到的输出如下: 点击查看