传递带有数组作为某些键的对象,以便在SQL Server中存储过程
因此,我正在与SQL Server合作,并且将API称为存储过程,将以下程序作为参数作为参数,
{
"Survey": "Satisfaction survey",
"Questions" : [
{
"Question": "Are you satisfied with the customer service?",
"Options" : [
{
"Option" : "Yes"
},
{
"Option" : "No"
},
{
"Option" : "No comment"
}
]
}
]
}
这只是一个裸露的骨头对象,还有更多键。该数据库具有称为调查,问题和选项的表。钥匙需要插入各自的表格。是否有可行的方法可以将对象作为参数传递,或者我应该修改对象以将其作为参数传递?任何帮助都将受到赞赏。
编辑:表格的模式如下
:问题:
SurveyID | bigint | primary key
Survey | varchar |
选项:
QuestionID | bigint | primary key
Question | varchar |
SectionID | bigint | foreign key
选项:
OptionID | bigint | primary key
Option | varchar |
QuestionID | bigint | foreign key
So I am working with SQL server and the API is supposed call a stored procedure passing the following as parameter
{
"Survey": "Satisfaction survey",
"Questions" : [
{
"Question": "Are you satisfied with the customer service?",
"Options" : [
{
"Option" : "Yes"
},
{
"Option" : "No"
},
{
"Option" : "No comment"
}
]
}
]
}
This is just a bare bones objects and there are many more keys. The database has tables called surveys, questions, and options. The keys need to be inserted in their respective tables. Is there a feasible way to pass the object as a parameter or should I modify the object to pass it as a parameter? Any help is appreciated.
EDIT : the schema of the tables are as follows
Survey:
SurveyID | bigint | primary key
Survey | varchar |
Questions:
QuestionID | bigint | primary key
Question | varchar |
SectionID | bigint | foreign key
Options :
OptionID | bigint | primary key
Option | varchar |
QuestionID | bigint | foreign key
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我尝试使用@zhorov的第一个评论中提到的OpenJson()。它给了我所需的结果。我遵循以下文档
https://learn.microsoft.com/en-us/sql/t-sql/functions/openjson-transact-sql?view=sql-sql-server-ver16
I tried using OPENJSON() as mentioned in @Zhorov 's first comment. It is giving me the needed results. I followed the following documentation
https://learn.microsoft.com/en-us/sql/t-sql/functions/openjson-transact-sql?view=sql-server-ver16