数据库结构,关系还是数据仓库?

Han*_*del 5 sql-server-2008 data-warehouse database-design relational-theory

早上好,

我在如何布置我的数据库方面遇到了一些问题,希望得到一些指导。我有几个表(降雨量数据),每个表都包含以下列:

Date (DateTime), Value_of_rainfall (Float)
Run Code Online (Sandbox Code Playgroud)

这些表中的每一个都用于特定位置。

有人建议我创建另一个包含以下列的表:

LocationID (tinyInt), LocationName(char(6))
Run Code Online (Sandbox Code Playgroud)

并在第一个表中插入一个名为 LocationID(tinyInt) 的新列。

现在我的困惑是关于我存储在降雨数据数据表中的数据。建议将来自每个位置的所有数据包含在一个数据表中。我希望对信息进行的统计分析非常(就我迄今为止所设想的)位置特定,并且不需要一次查询多个位置。一个位置几个月的数据 = 近 300 万行,我希望对数据进行长时间运行的计算。那么数据仓库会更合适吗?如果是这样,有人可以给我一些关于我应该如何布置它的指示吗?

谢谢你的时间。

注意:我使用的是 Sql Server 2008

Con*_*lls 10

似乎您想要聚合基于位置的降雨统计数据。像下面这样的数据库结构可以让你做到这一点。“数据源”可能只是一个文件名,或者它来自哪里的一些指示。

create table DimDataSource (
       DataSourceID      int identity (1,1) not null
       DataSourceDesc    nvarchar (100)  -- May need unicode for file names
)
go

alter table DimDataSource
  add constraint PK_DataSource
      primary key clustered (DataSourceID)
go

create table DimLocation (
       LocationID        int identity (1,1) not null
       LocationDesc      varchar (50)
)
go

alter table DimLocation
  add constraint PK_Location
      primary key clusterd (LocationID)
go

create table DimDate (
       DateID           smalldatetime not null  -- 'Date' is a reserved word
      ,MonthID          int not null
      ,MonthDesc        varchar (15)
      ,QuarterID        int not null
      ,QuarterDesc      varchar (15)
      ,YearID
)
go

alter table DimDate
  add constraint PK_Date
      primary key clustered (DateID)
go

create table DimTime (
       TimeID           time not null  -- 'Time' is a reserved word
      ,Hour             int not null
)
go

alter table DimTime
  add constraint PK_Time
      primary key clustered (TimeID)
go


-- If the table is <50GB, don't bother with partitioning, but put a clustered
-- index on DateID or LocationID and DateID, depending on how you normally expect
-- to query the data.

create table FactRainfall (
       RainfallID        int identity (1,1) not null -- May need a wider type if >4B rows.
                                                     -- SSAS likes an identity column for
                                                     -- incremental loads
      ,DataSourceID      int not null
      ,LocationID        int not null
      ,DateID            smalldatetime not null
      ,TimeID            time not null
      ,Rainfall          float
)
go

-- Add foreign keys as necessary
Run Code Online (Sandbox Code Playgroud)

使用适当的位置列表、日期范围、一天中的时间以正确的粒度和每个文件的一个数据源记录填充维度。此表还允许您在顶部放置一个立方体,或者可以用视图展平,这将帮助人们使用 Excel 或 stats 包等工具来获取和使用数据。