This is something I should really know, but I haven’t done any db work for quite a while and just wanted some clarification on a structure for a simple mysql database.
The basic premise is a shopping cart – so we have catalogue, customer and orders.For now, the customer isn’t going to sign up, they will enter details every time.
My main struggle is how to structure the customer and order table as obviously it would be good to have these separate.
Is the best method just to have the customer table with an fkey to the order table, and the order table simply references the item in the catalogue with another fkey?
Any clarification is much appreciated.
You have 4 tables at the very basic level:
users,basket,items,basket_items.Orders would work just like
basketandbasket_itemsso let’s keep it simple for now.A Record in
basket_itemsis just abasket_idand anitem_id– it’s a link table used for resolving this kind of many-to-many relationship (eachbaskethas manyitems, eachitemcan be in manybaskets).The
basketororderstable, as you say, just have a foreign key to thecustomerstable – each order is by one, and only one customer.