OPENJSON 在 SQL Server 中不起作用?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36470782/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 18:23:05  来源:igfitidea点击:

OPENJSON does not work in SQL Server?

sql-serverjsonsql-server-2016

提问by Iva

I want to use JSON functions in SQL Server 2016, but when I try to execute OPENJSONfunction, I get the following error:

我想在 SQL Server 2016 中使用 JSON 函数,但是当我尝试执行OPENJSON函数时,出现以下错误:

Msg 208, Level 16, State 1, Line 1
Invalid object name 'openjson'.

消息 208,级别 16,状态 1,第 1 行
无效的对象名称“openjson”。

Why it does not work? I have SQL Server 2016 RC version.

为什么它不起作用?我有 SQL Server 2016 RC 版本。

回答by Jovan MSFT

Could you check compatibility level on database? OPENJSON is available under compatibility level 130. Could you try to execute:

你能检查数据库的兼容性级别吗?OPENJSON 在兼容级别 130 下可用。您可以尝试执行:

ALTER DATABASE database_name SET COMPATIBILITY_LEVEL = 130

Also, if you are using JSON on Azure SQL Database, note that even new databases are created under 120 compatibility level so you should change it if you want to use OPENJSON. Also, if you are using it in Azure SQL Database, run select @@version to see is this V12 server. You should see something like:

此外,如果在 Azure SQL 数据库上使用 JSON,请注意,即使是在 120 兼容级别下创建的新数据库,如果要使用 OPENJSON,也应该更改它。此外,如果您在 Azure SQL 数据库中使用它,请运行 select @@version 以查看此 V12 服务器。你应该看到类似的东西:

Microsoft SQL Azure (RTM) - 12.0.2000.8 Mar 25 2016 15:11:30 Copyright (c) Microsoft Corporation

Microsoft SQL Azure (RTM) - 2016 年 3 月 25 日 12.0.2000.8 15:11:30 版权所有 (c) Microsoft Corporation

If you see some lower version (e.g. 11.xxx) you probably have database on old architecture where JSON is not supported.

如果您看到一些较低版本(例如 11.xxx),您可能在不支持 JSON 的旧架构上拥有数据库。

Regards,

问候,

Jovan

约万