规范化 - 重复外键

时间:2012-10-30 13:13:23

标签: database foreign-key-relationship database-normalization

规范化数据是否可以在同一个表中重复输入外键?

e.g。快递公司有一个订单表格和一个客户表格,订单表格会记录哪个客户从(Customer_ID)取货一个项目,并且还有一个列用于交付给客户的客户(也是Customer_ID)。

1 个答案:

答案 0 :(得分:2)

完全可以接受;这两个指数将分开维护。这两种关系可以单独使用......

select item, name, address from orders inner join customers on orders.sender = customers.id where orders.id = 5;
select name, address from orders inner join customers on orders.recipient = customers.id where orders.id = 5;

或在一起(小心)

select item, name as sender_name, address as sender_address, recipients.name as as recipient_name, recipients.address as recipient_address from orders inner join customers on orders.sender = customers.id inner join customers as recipients on orders.recipient = recipients.id;

小心删除级联;)