Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OPENJSON does not work in SQL Server?

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

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

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

like image 320
Iva Avatar asked Apr 07 '16 08:04

Iva


People also ask

How do I query JSON data in SQL?

To query JSON data, you can use standard T-SQL. If you must create a query or report on JSON data, you can easily convert JSON data to rows and columns by calling the OPENJSON rowset function. For more information, see Convert JSON Data to Rows and Columns with OPENJSON (SQL Server).

Can you parse JSON in SQL?

OPENJSON() function parses JSON in SQL Server In this context, the conversion of the JSON data into the relational format is becoming more important. OPENJSON is a table-valued function that helps to parse JSON in SQL Server and it returns the data values and types of the JSON text in a table format.

How do I change the compatibility level in SQL Server?

It's really simple to change the database compatibility level. In SQL Server Management Studio (SSMS), right-click on the database name, select Properties, select the Options node, click on the drop-down next to Compatibility level and select the level that matches your SQL Server.

How do I find the compatibility level in SQL Server?

Right-click the database, and then select Properties. The Database Properties dialog box opens. In the Select a page pane, select Options. The current compatibility level is displayed in the Compatibility level list box.


1 Answers

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

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:

Microsoft SQL Azure (RTM) - 12.0.2000.8 Mar 25 2016 15:11:30 Copyright (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.

Regards,

Jovan

like image 194
Jovan MSFT Avatar answered Sep 19 '22 09:09

Jovan MSFT