传递带有数组作为某些键的对象,以便在SQL Server中存储过程

发布于 2025-02-03 06:40:29 字数 957 浏览 4 评论 0原文

因此,我正在与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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

魂牵梦绕锁你心扉 2025-02-10 06:40:29

我尝试使用@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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文