0

我目前正在创建一个应该使用 SQLite 数据库的 Android 应用程序。就我而言,我需要存储“产品类型”、“账单”和“所有购买产品的列表”

账单:

id
customer
data -> link to list of all purchased products
price

产品类型:

id
name
price

我的问题是:一位客户可能有更多产品与一张账单相关联。如何设计它?为每张账单使用一行:

id
bill_id
product

或者更确切地说将更多产品插入一行,然后在我的应用程序中解析它?我想,有比这些我的更好的解决方案。谢谢你的帮助。

4

2 回答 2

3

您在问题中说,“一位客户可以将更多产品与一张账单相关联。”

另一种说法是,一个客户可以有 0 个或多个帐单,一个帐单可以有 1 个或多个产品。

改写您的语句后,数据库规范化变得更加明显。

Customer
--------
Customer ID
Customer Name
...

Bill
----
Bill ID
Customer ID
Bill Time Stamp

Bill-Product
------------
Bill ID
Product ID

Product
-------
Product ID
Product Name
Product Price
...
于 2013-09-04T14:07:44.723 回答
0

要设计带有账单的客户订单,我们可以设计如下:

此模式具有基本属性,我们可以根据需要添加更多属性。

客户表

身份PK

全名

地址

电话

菜单项表

身份PK

项目名

商品描述

item_price

订单表

身份PK

customer_id FK

订购日期

订单明细表

身份PK

order_id FK

menu_item_id fk

数量

账单表

身份PK

order_id FK

数量

账单日期

于 2016-04-08T06:51:22.613 回答