简体   繁体   English

试图找出一个好的数据库设计

[英]trying to figure out a good database design

OK here is my problem I am trying to design a database for a class project.好的,这是我的问题,我正在尝试为课堂项目设计数据库。 I am having a difficult time with figuring out how to relate one table to another.我很难弄清楚如何将一张桌子与另一张桌子联系起来。 In this instance i am trying to have a Primary key that can represent several different items.在这种情况下,我试图拥有一个可以代表几个不同项目的主键。 Like a single PizzaOrderID representing both a meat lovers, veggie lovers, and a cheese pizza.就像一个 PizzaOrderID 代表肉食爱好者、素食爱好者和奶酪披萨。 all with different quantities of pizzas.都有不同数量的比萨饼。 Can someone please help me out with how I might be able to set up this design?有人可以帮我解决如何设置这个设计吗?

Edit:编辑:

Third Normal Form第三范式

Customer顾客

Customer ID → Primary Key客户 ID → 主键

first name last name street address Apartment City State Zip Code Home phone mobile phone Other phone名字姓氏街道地址公寓城市州邮政编码家庭电话手机其他电话

Doughnut甜甜圈

Doughnut ID → Primary Key甜甜圈 ID → 主键

Name Description名称 说明

Doughnut Order甜甜圈订单

Doughnut Order ID → Primary Key甜甜圈订单 ID → 主键

Doughnut ID → Foreign Key甜甜圈 ID → 外键

Quantity Unit Price数量 单价

Order Sales订单销售

Order → Primary Key顺序 → 主键

Doughnut Order ID → Foreign Key甜甜圈订单 ID → 外键

ok this what i had as my third normal form as you can see the exact item i am dealing with is doughnuts i am guessing i need to adjust this form好的,这就是我的第三范式,因为您可以看到我正在处理的确切项目是甜甜圈,我猜我需要调整此表格

Let's start from the beginning.让我们从头开始。 You have a table representing meals, which you apparently call pizza and this table has a primary key pizza_id .您有一张代表餐点的表,您显然将其称为披萨,并且该表有一个主键izza_id (I use _ for readability). (我使用 _ 来提高可读性)。 Such meal can be ordered at a restaurant table, by putting an order stored in another table with primary key order_id .通过将存储在另一个表中的订单与主键order_id一起,可以在餐厅的餐桌上订购此类餐点。

So far so good.到现在为止还挺好。 Now the order can be for one pizza, two, or more of them.现在订单可以是一份披萨、两份或更多披萨。 Moreover the order can contain more pizzas of the same kind!此外,订单可以包含更多同类比萨! Apparently your design needs to cover for this and the solution is N:M (many to many) relation.显然,您的设计需要涵盖这一点,解决方案是 N:M(多对多)关系。

This is done in the third table called orderitem with a compound primary key (composed from two columns) pizza_id and order_id .这是在名为orderitem的第三个表中完成的,该表具有复合主键(由两列组成) pizza_idorder_id These two are simultaneously foreign keys referring to their respective tables.这两个同时是引用各自表的外键。 As additional column can be put amount of the meals, which are of the same kind.作为附加列可以放置相同种类的膳食数量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法找出正确的数据库设计 - Unable to figure out correct database design 试图弄清楚为什么一个sub导致27个条目进入mysql数据库 - Trying to figure out why a sub is causing 27 entries into a mysql database 良好的数据库设计/规范化 - Good Database design/normalisation 找出数据库死锁 - Figure out database deadlock 找出数据库问题 - Figure out database problems 什么是出勤数据库的良好数据库设计(架构)? - What is a good database design (schema) for a attendance database? 数据库-什么是预订系统的良好数据库设计? - Database - What is a good database design for a booking system? 试图使用vb.net将记录输入到mysql数据库中,但它不起作用,我无法弄清为什么 - Trying to enter records into a mysql database using vb.net but its not working and I cant figure out why 试图找出如何编写SQL查询以返回mysql数据库的两个表的非交叉,遇到问题 - Trying to figure out how to write an SQL query to return the nonintersection of two tables for a mysql database, having trouble 尝试将更改从 STAGING 站点推送到 LIVE 站点(均为 WordPress),但我试图找出可供选择的数据库项目 - Trying to push changes from STAGING site to LIVE site (both WordPress) but I'm trying to figure out which database items to choose from
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM