提取重复出现的 blob 数据并放入另一个 table 的最佳方法是什么? - SQL

What is the best method to extract a recurring blob data and put in another table ? - SQL

我正在为以下场景在(.NET 框架,如果有帮助的话)中开发一个新网页。每一天,我们都会收到出租车 driver 的报告。

 Date   |  Blob 
-------------------------------------------------------------
15/07   |  {"DriverName1":"100kms", "DriverName2":"10kms", "Hash":"Value"...}
16/07   |  {"DriverName1":"50kms", "DriverName3":"100kms", "Hash":"Value"}

请注意,'Blob' 是以 json 格式接收的实际数据 - 包含有关 driver 在特定日期所走距离的信息。

我写了一个服务,读取上面的 table 并进一步分解它并将它放入一个新的 table 中,如下所示:

Date  |  DriverName   | KmsDriven

15/07    DriverName1     100
15/07    DriverName2      10
16/07    DriverName3     100
16/07    DriverName1      50

通过填充它,我可以轻松地执行以下查询:

  1. 那天有多少 driver 开车。

  2. 'DriverName1' 那一周的表现如何,等等,

我的问题是:

  1. .NET / SQL world 中有什么特别的 解决这个问题,或者如果我在这里重新发明轮子,请告诉我。
  2. 这是使用 Blob 数据的正确方法吗?
  3. 是否有任何设计模式需要遵守?
  1. Are there anything in .NET / SQL world to specifically address this or let me know if I am reinventing the wheel here.

嗯,有 JSON 个解析器可用,例如 Newtonsoft's Json.NET. Or you can use SQL Server's own functions。从 JSON 中提取单个值后,您可以将它们写入相应的列(在新的 table 中)。

  1. Is this the right way to use the Blob data?

没有。它违反了atomicity的原则,因此违反了第一范式。

  1. Are there any design patterns to adhere here to?

我不确定 "patterns",但我不明白为什么在这种情况下需要 BLOB。

假设数据是统一的(即它总是具有相同的字段),您可以只声明您需要的列并直接写入它们(正如您已经提议的那样)。

否则,您可以考虑使用 SQL 服务器的 XML data type,这将使您能够提取 XML 文档中的某些部分,或者插入一个新部分而无需替换您的整个文档。