如何删除存储在SQL Server列中的JSON属性? [英] How can I remove JSON property stored in a SQL Server column?
问题描述
我有一个任务要删除保存在SQL Server数据库表的列中的JSON属性.这是我的桌子的结构
I have a task to remove a JSON property saved in a SQL Server database table's column. Here is the structure of my table
OrderId Name JSON
在JSON
列中,我具有以下JSON数据:
In the JSON
column I have this JSON data:
{
"Property1" :"",
"Property2" :"",
"metadata-department": "A",
"metadata-group": "B"
}
我有500多个具有此json值的记录.
I have over 500 records that have this json value.
我可以更新所有记录以删除metadata-department
吗?
Can I update all the records to remove metadata-department
?
推荐答案
这个问题很旧,但我想为那些可能会通过搜索引擎出现在这里的人发布另一个解决方案.
This question is old but I thought I'd post another solution for those who may end up here via search engine.
在SQL Server 2016或SQL Azure中,以下工作正常:
In SQL Server 2016 or SQL Azure, the following works:
DECLARE @info NVARCHAR(100) = '{"name":"John","skills":["C#","SQL"]}'
PRINT JSON_MODIFY(@info, '$.name', NULL)
-- Result: {"skills":["C#","SQL"]}
来源: https://msdn.microsoft.com/en-us/library/dn921892.aspx
这篇关于如何删除存储在SQL Server列中的JSON属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!