SQL - Insert json array into multiple tables with identity

476 views Asked by At

Here is the example json -

     "Root Node - Type 1": {
                "Attributes": {
                    "Items": [
                        {
                            "A": {
                                "Value": "A1"
                            },
                            "B": {
                                "Value": "B1"
                            },
                            "C": {
                                "Value": "C1"
                            },
                            "D": {
                                "Value": "D1"
                            }
                        },
                        {
                            "A": {
                                "Value": "A2"
                            },
                            "B": {
                                "Value": "B2"
                            },
                            "C": {
                                "Value": "C2"
                            },
                            "D": {
                                "Value": "D2"
                            }
                       }
            ]
    }
}

I need to insert A, B in table 1 and take the identity from table 1 and insert into table 2. Also, I need to insert C, D into table 3. Items here will be a large array. I am looking to bulk insert this data into tables. Any ideas?

Table structure -

 CREATE TABLE [Table 1](
 [Id] [int] IDENTITY(1,1) NOT NULL,
 [A] [varchar](100) NULL,
 [B] [varchar](15) NULL,
 [CreatedBy] [varchar](255) NULL,
 [CreatedDate] [datetime] NULL


 CREATE TABLE [Table 2](
 [Id] [int] IDENTITY(1,1) NOT NULL,
 [Table1_Id] int,
 [CreatedBy] [varchar](255) NULL,
 [CreatedDate] [datetime] NULL

 CREATE TABLE [Table 3](
 [Id] [int] IDENTITY(1,1) NOT NULL,
 [Table1_Id] [int] NOT NULL,
 [Name] [nvarchar](100) NOT NULL,
 [Value] [nvarchar](1000) NULL

Data 0 enter image description here

0

There are 0 answers