Skip to content
Advertisement

How to insert JSON file data to SQL Server table using sql command

I am not so familiar with SQL.

I have a table in my SQL Server database called Product

I have a JSON file (which locates in D:demomyjson.json) where stores all my product info like:

How can I write sql to get this file and import data into my Product table instead of manually doing this?

I am using SQL Server 2016 and SSMS.

Advertisement

Answer

You may try an approach, which uses OPENROWSET() (to read the file) and OPENJSON() with explicit schema (tp parse the input JSON). Note, that OPENROWSET() needs additional permissions. If the file contains unicode (widechar) input you should use SINGLE_NCLOB.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement