为一个购物车应用程序设计一个数据库?[英] design a database for a shopping-cart application?

本文是小编为大家收集整理的关于为一个购物车应用程序设计一个数据库?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我从未从头开始设计数据库/数据模型/模式,尤其是用于Web应用程序. 在最近的一些工作面试中,我被要求"设计"一个用于购物车应用程序的数据库.现在,我正在研究移动购物应用程序(零售,使用PhoneGap),其后端需要存储和处理产品和订单信息.这个问题的规模是如此之大,我不知道从哪里开始.我希望对 -

提供一些建议
  1. 我应该如何解决这样的问题(购物车应用程序DB)?我应该从哪里开始?
  2. 我应该避免任何常见的错误/陷阱吗?
  3. 在设计这样的DB时,我应该牢记哪些优化/效率范例?
  4. 我应该如何确定问题空间(产品,订单等)中的实体?我应该如何得出它们之间的关系?
  5. 当面试官问这样的问题时,他到底在寻找什么?我应该/不应该说些什么吗?

我也应该澄清 -

  1. 是的,我是一个菜鸟,我的动机是学习数据库设计并为即将进行的求职面试做准备.我已经阅读了DBMS书籍,它们可以详细描述单个概念,但是我不知道如何将这些内容放在一起并开始设计数据库.
  2. 我在数据库设计上看到了其他线程.作者已经倾向于对如何解决问题有一些知识.我想了解这样做的方法.
  3. 链接到外部资源,评论,建议以及任何将使我走上正确的轨道的链接.我希望这个线程为我自己和他人充当学习经历.

推荐答案

数据库中可以有五个表:

类别此表存储有关商店和类别层次结构的产品类别的信息.
此表的父字段存储父母类别的ID.

产品您商店的所有产品都存储在此表中.该表具有一个外键类别ID,该类别标识了产品所属类别的ID.

订单此表存储有关商店访问者的所有订单的信息.

ordered_shopping_cart 表与产品和订单表紧密连接;存储有关客户订单内容的信息.

special_offer 表包含一个产品列表,在主页上显示为特殊报价

其他推荐答案

一个简短的答案是我解决这个问题的方式.首先,有大量的开源或免费的基于Web的购物车.这意味着您可以得到一个,设置数据库,然后仔细看看他们的所作所为.

问自己这样的问题,为什么他们这样做?为什么好吗?有什么缺点?我将如何做不同?为什么?

我会尝试采购一个数据库设计工具,使您可以可视化数据库. (例如Visual Studio中的数据库设计器,或者我有一个来自Microlap的PGSQL数据库)

)

然后,您需要考虑数据库中的需求.客户要做什么?买产品!因此,您需要一个产品表.在不走整个路线的情况下,您可以看到这一点.想象一下需要什么,然后基本上为它做一个桌子.

如果表格中的字段有多个选项,请在其中制作另一个表格.因此,如果您有产品表,并且有一个状态字段.您可以拥有多个状态. (例如库存,有限的数量,大项目,昂贵),而不是硬编码这些字段,制作一个表并允许用户将项目添加到表中.然后在产品表中添加字段status_id并将其链接到状态表

许多人 - 许多关系都是有用的知识. (我本人不对这个.)说您有一个组件和产品表.这些产品可以由许多组件组成,并且可以将组件分配给许多产品.创建一个调解人表.诸如ProdComp之类的东西(在此中,您将拥有ID,prod_id,comp_id,qtyneded的字段).

学习到正确.

在您对如何工作有一个扎实的了解之前,不要创建数据库.这节省了稍后重新创建的时间.

可能还有更多,但是我希望我给了您一个好的开始.

本文地址:https://www.itbaoku.cn/post/597661.html

问题描述

I have never designed a database/data-model/schema from scratch, especially for a web-application. In some recent job interviews, i was asked to 'design' a database for a shopping cart application. Now i am working on a mobile shopping application (retail, uses phonegap) with a backend that needs to store and process product and order info. The scale of this problem is so huge, i don't know where to start. I was hoping for some advise on -

  1. How should I approach such a problem (shopping cart application DB) ? where should i start ?
  2. Are there any common mistakes/pitfalls that i should avoid ?
  3. What optimization/efficiency paradigms should i keep in mind when designing such a DB ?
  4. How should i go about identifying entities in the problem space (products, orders, etc)? how should i derive the relationships between them ?
  5. When a interviewer asks such a question, what exactly is he looking for ? is there something i should/should not say ?

I should also clarify that -

  1. Yes, I am a noob, and my motives are to learn database design AND prepare for upcoming job interviews. I have read DBMS books where they describe individual concepts in detail, but i have no clue how to put those things together and start designing a database.
  2. I have seen other threads on database design. The authors already tend to posses some knowledge on how to break the problem down. i would like to understand the methodology behind doing that.
  3. Links to outside resources, comments, suggestions and anything that will put me on the right track is much appreciated. I hope this thread serves as a learning experience for myself and others.

推荐答案

There can be five tables in database:

CATEGORY this table stores information about products categories of your store and categories hierarchy.
parent field of this table stores ID of the parent category.

PRODUCT all products of your store are stored in this table. This table has a foreign key categoryID which identifies ID of the category to which a product belongs.

ORDER this table stores information about all orders made by visitors of your store.

ORDERED_SHOPPING_CART table is tightly connected with PRODUCT and ORDER tables; stores information on customers' orders content.

SPECIAL_OFFER table contains a list of products, which are shown on home page as special offers

其他推荐答案

A brief answer is the way that i would tackle this problem. Firstly, there are loads of open source or free, web based shopping carts. This means that you can get one, set up the database and then have a good look around what they did.

Ask yourself questions such as, why have they done that? Why is it good? What downside could there be? How would i do it differently? why?

I would try to procure a database design tool that allows you to visualize the database. (like database designer in visual studio or i have one from MicroOlap that does pgsql databases)

Then you need to think about what you need in the database. What is the customer going to do? Buy products! Therefore you need a products table. Without going down the whole route you can see the point. Imagine what is needed, then basically make a table for it.

If you have more than one option for a field in a table, make another table with a relation in it. So if you have a product table and you have a status field. you could have more than one status. (eg out of stock, limited number, big item, expensive) instead of hard coding these fields, make a table and allow the user to add items to the table. then in the product table add a field status_id and link it to the status table

Many - many relationships are useful things to know. (i fell short to this myself.) say you have a component and product tables. The products can be made up of lots of components and the components could be allocated to many products. Create a mediator table. Something like prodcomp( and in this you would have fields like id, prod_id, comp_id, qtyneeded).

Learn to index correctly.

Don't create the database until you have a solid idea of how it will work. this saves time in recreating it later.

There may be more to this, however, i hope i have given you a good start.