它歸結於design
的intention
。這裏有一些了許多---許多的辦法---採取:結合
-- stores info re:reason for the last update of a subscription
CREATE TABLE subscription_history (
subscription_id INT
, change_date DATETIME
, change_reason VARCHAR(255)
)
或者歷史表的查找:
你可以使用一個歷史表
-- stores info re:reason for the last update of a subscription
-- but links to a change_reason table for reason id lookups
CREATE TABLE subscription_history_L (
subscription_id INT
, change_date DATETIME
, change_reason_id INT
)
-- lookup table containing change reasons
CREATE TABLE change_reason (
change_reason_id INT
, change_reason VARCHAR(255)
)
或審計表V1:
-- contains all columns in your subscription table plus audit fields
CREATE TABLE subscription_audit (
subscription_audit_id INT
-- All the fields from your `subscriptions` table
, audit_date DATETIME
, audit_reason VARCHAR(255)
, audit_by VARCHAR(255) -- example
-- etc etc whatever other information that is pertinent to the change
)
或審計表V2:
-- this could also act like a history table, so you can change the table name/purpose
CREATE TABLE subscription_audit (
subscription_id INT
, modified_column VARCHAR(255)
, value_old VARCHAR(255)
, value_new VARCHAR(255)
, modified_date DATETIME
) -- Drawback here is that you'll have one audit record per column
-- , and you may have to add extra columns for other data types
-- , or convert your values to varchar or something else.. which isn't
-- a really good idea! I just want to present this in case you can
-- develop the idea you find interesting further
我不知道你的RDBMS,但是這幾乎是一般SQL(我想我可以作爲一種方法更好的使用比文字和語言來解釋)
謝謝,很明顯。要檢查訂閱的狀態(例如,當他們嘗試登錄時),您會查詢SUBSCRIPTION_EVENT_MAP中的最新相關記錄嗎? – eoinoc 2011-12-23 16:51:25
@eoinoc是,最新的記錄按時間戳記。 – Glenn 2011-12-23 17:53:04