oracle日志表设计,数据库设计 – 数据库日志表结构
因為只有幾個不同的屬性,所以我會遠離名稱 – 值對,并為每個屬性提供一個具有正確名稱和數據類型的單獨表.我使用了通用Property_,僅用于演示.
這里的事情是確保在缺少屬性表時不插入值,換句話說,所有屬性值都是NOT NULL.
為了讓生活更輕松,請定義視圖
create view dbo.vLogs AS
select
LogCategoryName
, LogTime
, p1_Value
, p2_Value
, p3_Value
, p4_Value
, p5_Value
from LogEntry as e
left join Property_1 as p1 on p1.LogEntryId = e.LogEntryId
left join Property_2 as p2 on p2.LogEntryId = e.LogEntryId
left join Property_3 as p3 on p3.LogEntryId = e.LogEntryId
left join Property_4 as p4 on p4.LogEntryId = e.LogEntryId
left join Property_5 as p5 on p5.LogEntryId = e.LogEntryId
left join LogEntryCategory as x on x.LogEntryId = e.LogEntryId
left join LogCategory as c on c.LogCategoryID = x.LogCategoryID
這個視圖(查詢)看起來復雜而漫長;但是,如果您嘗試下面的查詢并查看執行計劃,您可能會注意到選擇列表中未提及的屬性表未包含在計劃中(未觸及).
select
LogCategoryName
, LogTime
, p1_Value
, p2_Value
from dbo.vLogs
where LogCategoryName = 'some_category'
and LogTime between from_time and to_time
如果你需要像這樣簡單的東西
select max(p1_Value)
from dbo.vLogs
where LogTime between '2011-07-18' and '2011-07-19'
這是執行計劃,因為您只能看到涉及兩個表.
這稱為表(連接)消除,你需要SQL Server,Oracle,PostgreSql 9.x,…為此工作 – 將無法在MySql(尚未)上工作.
每次添加屬性時,都必須添加新表并修改視圖.
總結
以上是生活随笔為你收集整理的oracle日志表设计,数据库设计 – 数据库日志表结构的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 香港恒生指数代码
- 下一篇: android sqlite触发器,SQ