帮助设计披萨店的数据库架构

发布于 2024-10-26 01:22:56 字数 931 浏览 1 评论 0原文

这是脚本:

create table Customer
(
CustomerId int primary key identity(1,1),
Name nvarchar(64) not null,
LastName nvarchar(256) not null,
Telephone nvarchar(32),
MobilePhone nvarchar(32),
Address nvarchar(256)
)

create table Product
(
ProductId int primary key identity(1,1),
Name nvarchar(64),
Price decimal
)

create table StoreOrder
(
StoreOrderId int primary key identity(1,1),
Date datetime,
CustomerId int foreign key references Customer(CustomerId),
Total decimal
)

create table ProductStoreOrder
(
ProductStoreOrderId int primary key identity(1,1),
StoreOrderId int foreign key references StoreOrder(StoreOrderId),
ProductId int foreign key references Product(ProductId),
Quantity int
)

我对如何处理配料感到困惑。我应该能够在数据库中的某个位置添加配料并创建具有 N 种配料的披萨,每种配料还应该有一个相关的价格。

可以创建一个配料表并将其与产品关联,但并非每个产品都有配料。例如,面包棒、无糖汽水、沙拉等。

处理这种情况的最佳方法是什么?另外,到目前为止对数据库设计有什么评论吗?

感谢您抽出时间。

Here's the script:

create table Customer
(
CustomerId int primary key identity(1,1),
Name nvarchar(64) not null,
LastName nvarchar(256) not null,
Telephone nvarchar(32),
MobilePhone nvarchar(32),
Address nvarchar(256)
)

create table Product
(
ProductId int primary key identity(1,1),
Name nvarchar(64),
Price decimal
)

create table StoreOrder
(
StoreOrderId int primary key identity(1,1),
Date datetime,
CustomerId int foreign key references Customer(CustomerId),
Total decimal
)

create table ProductStoreOrder
(
ProductStoreOrderId int primary key identity(1,1),
StoreOrderId int foreign key references StoreOrder(StoreOrderId),
ProductId int foreign key references Product(ProductId),
Quantity int
)

I'm confused on how to handle toppings. I should be able to add toppings in the database somewhere and create pizzas with N toppings, each topping should also have an associated price.

I could create a Toppings table and associate it to Product but not every product has a topping. For example, bread sticks, a diet soda, a salad, etc.

What would be the best way to handle this situation? Also, any comments on the database design so far?

Thank you for your time.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

べ映画 2024-11-02 01:22:56

我认为这是利用超/子类型数据库设计的一个很好的选择。这是一张快速绘图,我相信它可以解决您目前所担心的问题。这只是基础,您可以根据需要填写所需的属性和价格。

在此处输入图像描述

I think this is a good candidate to utilize a super/subtype DB design. Here is a quick drawing that I believe addresses the concerns you have at this point. This is just the base, you can take it and fill in the needed attributes and pricing as you are concerned about.

enter image description here

轻许诺言 2024-11-02 01:22:56

你可以尝试这样的东西:

  • 比萨饼、苏打水、棍子、沙拉都是
    产品表。
  • 产品有许多配料(连接表中两个表的外键,该连接表中的价格被驱逐)。

您可以在另一个表中定义产品“模板”后,定义类别以及产品是否具有配料或其他特殊属性。

You can try something like :

  • Pizzas, soda, sticks, salad are
    products table.
  • Products have many Toppings (foreign key of both table in a join table, price deported in the this join table )

After you can define products "template" in an another table, to define category and if product have Toppings or other special attributes.

小忆控 2024-11-02 01:22:56

遵循 @Andy 的建议,或者在产品表中添加一个布尔值,指示该产品是否是配料。

Go with @Andy 's suggestion, or add a boolean to the product table indicating whether the product is a topping or not.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文