代码之家  ›  专栏  ›  技术社区  ›  Harriv

多变量类型数据采集的数据库设计

  •  1
  • Harriv  · 技术社区  · 17 年前

    最简单的解决方案是一个包含变量FK、新值和时间戳的表,但由于变量可以有不同的类型,新值的类型会导致问题。我能想到的解决方案很少,都涉及单独的变量定义表和一个或多个时间序列表,每个变量值时间戳对应一条记录:

    1. 有一些可以存储所有值的通用数据类型(字符串?)
    2. 有多个数据值表,每种类型一个表

    2 回复  |  直到 17 年前
        1
  •  1
  •   JeeBee    17 年前

    create table foo_values (
      -- optional fkey to select which foo this key/value belongs to
      foo_uid number(18,0) not null enable,
      key nvarchar2(64) not null enable,
      -- could be a fkey to a table of types, or an enum, etc, 
      -- depending on database support  
      datatype number(2) not null enable, 
      value nvarchar(256)
      created timestamp default systimestamp not null enable,
    
      -- Foreign key and index stuff here, etc ...
    )
    
        2
  •  1
  •   vartec    17 年前