2010-03-27 31 views
2

嗨,大家好我正在我的基于Web的订购系统上工作,我们希望为我们的每个订单保持一种任务历史记录。从某种意义上说,我们希望记录谁在某个订单上做了什么,例如可以说订单已经输入 - 我们想知道订单是否被示例承认。或者可以说,有人跟进的顺序 - 等表设计问题 - 我应该创建单独的字段或存储为blob

认为有很多情况是这样每个订单这将是明智的创建上的线路架构:

Orders 
ID - title - description - date - is_ack - is_follow - ack_by ..... 

,加起来到很多领域 - 另一方面,我可以有一个名为“历史”的LongText字段,并填充一个包含所有信息的序列化对象。

但是在后一种情况下,我无法运行查询来让所有未被确认的订单以及类似的东西。随着时间的需求会改变,我将被要求修改它以允许更详细的跟踪,这就是为什么我需要设置一种可以扩展的方式,但我不想在SQL方面受到限制太多了。

编辑===================

所以斑想法有问题,然后:(但什么是我在这方面的选择。其实我都希望。管理是什么与订单那张历史一样,如果有人有:

  • 已确认附一封电子邮件给
  • 为了完成一个任务的顺序
  • 跟进
  • 的订单的订货
  • 打了电话etc

回答

0

boolean字段,你在这个例子中显示通常是不够的。我建议你创建其他表:

Status (ID, Value) - essentially enumeration of possible values: Received, Acknowledged, Dispatched, ... 
OrderStatus (ID, StatusID (FK to Status), AuditBy, AuditAt, Comment) 

您可以完全避免其Status表,只是在OrderStatus表中的列Status。但在这种情况下,至少应将可能的值限制在您拥有的列表中。

通过这种方式,您可以更好地审核发生了什么,何时以及由谁发出的审计追踪。

1

将逻辑上截然不同的信息混合在一起几乎总是一场灾难。减少实地计数本身并不是一个目标。

0

很少需要将信息存储为blob或xml。

当你这样做时,你开始失去你的数据库引擎提供的能力来有效地进行查询。

然后,您的查询将不得不与应用程序或专门的db代码一起处理,这似乎会使事情变得复杂。

而只是想着失去的能力,以索引列有我在结束X-毛)

1

没有真正想过这个通过,但你可以做这样的事情http://pastie.org/889605

从pastie一些片段:

drop table if exists order_events; 
create table order_events(
event_id int unsigned not null auto_increment primary key, 
order_id int unsigned not null, 
event_type_id tinyint unsigned not null, 
status_id tinyint not null, 
emp_id smallint unsigned not null, 
event_date datetime not null, 
key order_events_order_idx(order_id), 
key order_events_emp_idx(emp_id) 
)engine=innodb; 


drop table if exists event_type; 
create table event_type(
event_type_id tinyint unsigned not null auto_increment primary key, 
name varchar(255) 
)engine=innodb; 

insert into event_type (name) values ('new order event'),('order status event'); 

create trigger orders_after_upd_trig after update on orders 
for each row 
begin 
    -- change of status 
    if new.status_id <> old.status_id then 
    insert into order_events (order_id,event_type_id,status_id,event_date,emp_id) 
    values (old.order_id, 2, new.status_id, now(), new.updated_emp_id); 
    end if; 
end# 
相关问题