它归结于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