2017-04-12 195 views
0

我有以下架構表:插入到SQL Server 2016

tblStudent(id NEW ID(),Characteristics nvarchar(max)) 

我想用正常的INSERT INTO查詢,插入tblStudents.Characteristics列此JSON對象。

{ 
    "name": "Debashish Saha", 
    "Skills": [{ 
     "Domain": "cse", 
     "interest": "Data Structure" 
    }, { 
     "Domain": "Language", 
     "interest": "English" 
    }, { 
     "Domain": "Science", 
     "interest": "Maths" 
    }] 
} 

是我的json對象。

這是可能的!

+0

請注意這裏。它看起來像你的表有一個GUID作爲主鍵。這帶着一些你需要理解的包袱。 https://www.sqlskills.com/blogs/kimberly/guids-as-primary-keys-andor-the-clustering-key/ –

回答

0

這是一個簡單的插入語句。作爲JSON不會更改語法:

insert into tblStudent (Characteristics) 
values 
('{ "name": "Debashish Saha", "Skills": [{ "Domain": "cse", "interest": "Data Structure" }, { "Domain": "Language", "interest": "English" }, { "Domain": "Science", "interest": "Maths" }] }');