帮助设计披萨店的数据库架构
这是脚本:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为这是利用超/子类型数据库设计的一个很好的选择。这是一张快速绘图,我相信它可以解决您目前所担心的问题。这只是基础,您可以根据需要填写所需的属性和价格。
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.
你可以尝试这样的东西:
产品表。
您可以在另一个表中定义产品“模板”后,定义类别以及产品是否具有配料或其他特殊属性。
You can try something like :
products table.
After you can define products "template" in an another table, to define category and if product have Toppings or other special attributes.
遵循 @Andy 的建议,或者在产品表中添加一个布尔值,指示该产品是否是配料。
Go with @Andy 's suggestion, or add a boolean to the product table indicating whether the product is a topping or not.