Click here to Skip to main content
15,888,316 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hello,
Here is json which i want to store into database but the field "tagId" which has int datatype ,which accept multiple value from front end .so which way is best to solve this problem.

What I have tried:

{ 
"actiontaken":"safsaffsa",
"descript":"safsafaf",
"equip_type":"false",
"equipment":"afsafsa",
"history":"afasfd",
"licensor":"sss",
"netw_section":"tsadsarue",
"para_observation":"safdsaf",
"plantarea":"afssa",
"priorities":"tsdsrue",
"statuss":"Escalate",
"subject":"dsafsa",
"tagId":[{
  "tagId":4
},
{
  "tagId":4
}
]
}
Posted
Updated 2-Jun-17 9:46am
Comments
F-ES Sitecore 2-Jun-17 10:50am    
Have a one-to-many relationship with the main data in the json being in the "one" table and the tag ids in the "many". To preempt your next question, google "sql one to many relationship" for specific details.

I would recommend PostgreSQL which has a special json field, see: PostgreSQL JSON Tutorial[^]
We have migrated from SQL Server to PostgreSQL a year ago and never regretted it.
We use C# in combination with the NpgSql driver for PostgreSQL.

If you want to try PostgreSQL, there is also a portable version available.
You can also try SQL Fiddle, they have a nice PostgreSQL example: SQL Fiddle[^]
 
Share this answer
 
v2
Comments
Richard Deeming 2-Jun-17 17:39pm    
If you migrated just for the JSON support, you left marginally too soon! :D

(See solution #2, and: JSON support in SQL Server 2016[^])
RickZeeland 3-Jun-17 3:21am    
No, we migrated to PostgreSQL because we had performance problems with big data and our customers did not want to fork out for extra servers etc.
Also PostgreSQL is much more compact and easier to deploy with our package.
But it is clear that Microsoft is feeling the hot breath of the PostgreSQL dragon as they are implementing these features too.
If you're using SQL Server 2016, you can for example store the JSON in a varchar column and use the built in functions to query the data.

Have a look at Cutting Edge - Query JSON Data in SQL Server 2016[^]
and JSON Data (SQL Server) | Microsoft Docs[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900