数据库设计,项目和订单表 [英] database design, items and orders tables

查看:233
本文介绍了数据库设计,项目和订单表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚对数据库设计做了一些投入。我有两个表,订单和项目。



项目表将是可以在多个订单上使用的项目列表,每个项目都有一个id

我以为这样做的方式是按顺序为每个项目添加逗号分隔的ids数组。



听起来像是最好的方式吗?
也可以使用linq到实体框架,我不认为id能够创建表之间的关系,但我不认为有必要反正有,因为这些项不是唯一的订单



感谢任何建议

解决方案

据我所知它不是很清楚),每个订单可以有多个项目,每个项目可以在多个订单中使用。如果这是你想要的,你有许多关系,必须使用交集实体来解决。该交集实体有2个外键,一个用于项目,一个用于订购。使用它,您可以确定什么项目是在一定的顺序和什么订单需要某个项目。



由于我的解释非常短,非常马虎,我会推荐你以下参考文献:



http://sd271.k12.id.us/lchs/faculty/bkeylon/Oracle/database_design/section5/dd_s05_l03.pdf



解决许多关系



此外,你提出的设计是非常糟糕的,因为它打破了第一个正常形式:没有属性可以有多个值。您尝试至少以第三种正常形式构建数据库。


I was just after some input on database design. I have two tables, Orders and Items.

The items table is going to be a list of items that can be used on multiple orders, each item has an id

The way i thought to do it at the moment, was in the order to put an array of comma seperated ids for each item in the order.

does that sound like the best way? also im using linq to entity framework and i dont think id be able to create a relationship between the tables, but i dont think one is needed anyway is there, since the items are not unique to an order

Thanks for any advice

解决方案

As far as I have understood from your question (it is not very clear), every Order can have multiple Items and every Item can be used in multiple orders. If this is what you want, you have a many to many relationship, that must be resolved using an intersection entity. This intersection entity has 2 foreign keys, one for item and one for order. Using it, you can identify what items are in a certain order and what orders need a certain item.

As my explanation is very short and very sloppy, I will recommend you the following references:

http://sd271.k12.id.us/lchs/faculty/bkeylon/Oracle/database_design/section5/dd_s05_l03.pdf

Resolve many to many relationship

Also, you proposed design is very bad, as it breaks the first normal form: no attribute can have multiple values. You shoud try to build databases at least in third normal form.

这篇关于数据库设计,项目和订单表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆