Sales Database - Not Working

Not entirely sure what you're asking here. I'd normalize between the order and order details table via a 1:* (many) relationship, rather than having rows 1-5. The order is a single entity, and the details hang off this.
 
does not work

Come on buddy we're not mind readers, I know you can do better than that.

Although I'm not sure that 'Detail' should be the primary key in your detail tab, as two orders might have the same detail e.g. '3mm screw' or whatever.
 
Last edited:
Item 1 through Item 5 are redundant.

Add a "Quantity" to the Order Details table (and consider renaming the table to OrderDetails).

To get the Product IDs in an order you would say

SELECT ProductId FROM OrderDetails
INNER JOIN Order ON Order.OrderID = @OrderId

or for product details

SELECT Products.* FROM Products
INNER JOIN Order ON Order.ProductId = Products.ProductId
WHERE Order.OrderId = @OrderId
 
Back
Top Bottom