Here's a database design for the order section in e-commerce, with products having multiple attributes and multiple prices:
Table: Users
UserID
: Primary key, unique integerUsername
: StringEmail
: StringPassword
: StringCreatedAt
: Date and timeUpdatedAt
: Date and time
Table: Orders
OrderID
: Primary key, unique integerUserID
: Foreign key referencing Users tableTotalAmount
: DecimalOrderDate
: Date
Table: OrderItems
OrderItemID
: Primary key, unique integerOrderID
: Foreign key referencing Orders tableProductID
: Foreign key referencing Products tableVariantID
: Foreign key referencing ProductVariants tableQuantity
: IntegerPrice
: DecimalSubtotal
: Decimal
Table: Products
ProductID
: Primary key, unique integerName
: StringDescription
: TextCreatedAt
: Date and timeUpdatedAt
: Date and time
Table: ProductVariants
VariantID
: Primary key, unique integerProductID
: Foreign key referencing Products tableName
: String (e.g., Color, Size)Value
: String (e.g., Red, XL)
Table: VariantPrices
PriceID
: Primary key, unique integerVariantID
: Foreign key referencing ProductVariants tablePrice
: DecimalCurrency
: String (e.g., USD, VND)
In this design, the OrderItems
table contains information about each item in an order, including details about the product, product variant, quantity, price, and subtotal.