MySQL design multi outlet products - mysql

A company has many products. It has many stores. Each store has different price and inventory to track.
My current DB Design is:
Products
ID product_name price inventory
Stores
ID store_name
ProductAttr
store_id product_id price inventory
Now I am saving the inventory and price in product table itself in case a new product is added in one of the stores and the ProductAttr table row is not created for other stores, in which case they can default to products table.
Is it better to have the attributes move to ProductAttr table completely. If they add a new store in few weeks time, I need to make sure all product attributes are created under this new store. Also when a store creates a product, to create rows for all the stores.
What would be the best approach to tackle this kind of situation?

You are thinking along the correct line. The inventory attribute should belong to ProductAttr as its a property related to that store's product.
You can futher add a default store, which can be assigned in case you don't have stores to assign.
The total product inventory will be the sum of inventory in ProductAttr table.

Related

Trying to get some information from different tables - comparison

I am trying to obtain the lowest price for a product from a table of product prices per store. Also, i want to validate if the amount entered by the user exist in the STOCK table as well.
Take note:
A user has an address and this address is associated with a zipcode.
The user will be able to choose different products from table
"Products", these products exist (or not) in different supermarkets
and the supermarkets have different zipcodes (in my model zipcodes
from table address and table market are the same).
Inside Products table there are multiple items that belong to
different supermarkets and they have different prices. I only want to
insert inside LIST table those items that have the lowest price
compared to other supermarkets. If an item has the lowest price but
the zipcode of the supermarket does not math to the zipcode that exist
in the user table then it will be inserted other register from the
other supermarkets (with the lower price). The stock will be checked
everytime
Take a look at this:
sqlfiddle
This is an example(i cannot upload images yet):
image
I have been trying so many times without success.I used min function in order to obtain the lower price:, ie:
SELECT idProduct
FROM product
WHERE price = (SELECT MIN(price) FROM product);
Then,i tried to use not exist function in order to solve this but i failed.
Could you please help me?

MySql: Store Database

I have a database I created for retail store data. I have three tables defined as follows:
Clients
id
name
Items
id
name
price
Purchases
id
client_id
item_id
So if the user enters a wrong Item name or price he would go to the item and make changes and it'll be fixed in all purchases (let's call this situation 1), but what if the product company decides to changes price for instance, if the user changes the price in item the previous purchases would changes as well. I thought of including the price in the Purchases table, but then situation 1 would be changing a lot of purchases.
My question is what is the best approach to work around this issue?
EDIT
Based on Gordon's comment, I did the following changes:
Items
id
name
price_id
Prices
id
price
effective_date
My question now is: I have more than 5000 item, wouldn't this slow my search?

How do I use lists in MySQL

How do I represent invoices into an MySQL table structure?
The invoice table has the following fields:
id
customer_id
services
tax
total_price
date
...
Now the services can contain one or more articles and, what makes it complicated, various prices. The actual price of a service is negotiated, there are seldom fixed prices because each customer has individual requirements. These items have to be listed on the invoice and the prices of each have to be listed and summarized + tax.
What is the best practice for this purpose? I want to make it normalized if possible, something more sophisticated than just saving an (serialized) array of service => price into the service field, if this is possible at all. Do I use a second table for each service + price and hold a list of IDs with foreign keys?
I think you should follow Has And Belongs To Many relationship. Fr that you use two more tables for this one is 'services' and other is 'invoice_services'
'services' table contain service info and its price etc.
'invoice_services' table will be the join table for 'invoice' and 'services' tables. 'invoice_services' table will contain 'service_id' and 'invoice_id'.
Then you can remove the column 'services' from 'invoice' table.
If you want to maintain negotiable price for each service, then you can add one more field 'custom_price' in 'invoice_services' table.
Then using joins you can fetch the relative data of any invoice.
Hope this may help :)

E-Commerce Database Design for Orders Table

I am designing a schema for E-Commerce app, in which I would have 3 tables i.e Orders, Products, Customers.
So Should we store customer_id and product_id in Orders table straightaway.
The limitation to this is when a product or customer updates their attributes( i.e product price or customer name ), the orders table doesn't reflect them.
For Ex: A Customer bought a product at $10, but later on the product price gets updated to $20.So now when we are referring to this order by product id we would get the result as it was bought at $20 instead of $10.
SOLUTION 1:
One solution would be to insert a new row into products table whenever an updates occur and perform a soft delete to that product so that it can be referenced from orders table.
SOLUTION 2:
Store most of the details in product and customer details in orders table.
SOLUTION 3:
Create a temporary table of customers and products whenever there is an update to these tables.
I am very much open to any other suggestions.
One thing that you seem to be missing is a orderLineItem table for anything other than the most simple solution, where there is one product/order.
Now, that being said, you can do the products table in several ways.
Assuming that price is your only variable in the products table that you want to change, you can have a separate pricePoints table, that would store the price for any item at any given time. You would then use the ID from this table in your orders table and use that to get to the productID from the products table. A slightly more inefficient way to store this (but faster for retrieval) would be to store both the productId and the pricePointId in the orders table.
You could also do this by simply storing the price paid amount in the orders table. This gives you a little more flexibility to add discounts and pricing rules. You do need to be concerned about auditing the price though if you do it this way. Why was this price charged for this line at this time is going to be a common question.
You need to know how much the customer paid for the product at any time. It's not so important to know how much the customer would have paid for the order if they bought it today.
Customers are a slightly different issue. Some of the information in a customer table is transient. Some of it has to be fixed for the order. Lets say that the customer has a name, address, billing address and shipping address. At the time of the order, the shipping and billing addresses have to be absolutely fixed. You don't want to go back in three weeks and discover that the shipping address was changed. But, by the same token, you might like the name to be updated if a customer changes their maiden name, for example.
Now, all that being said, we aren't going to design your schema for you. There are a lot of good resources out there for how to design a simple e-commerce database.

MySQL - Database Design Question - Valid Formal Norms

I have a 'customers' table. Each record contains a customer name, email, address, etc.
I have an 'skus' table. Each record contains the name of an SKU. e.g. "Super Software Bundle".
An SKU represents a purchaseable item at a single price point. The purchased item can include one or more products.
e.g. The SKU record named "Super Software Bundle" may represent two products: product1 and product2.
For usability/ease reasons, other tables need to keep track of not only skus purchased, but the individual products a customer may have access to.
Question: how should I represent the variable sized nature of the SKUs in the database, where an SKU can represent from 1 to n products? Thanks for any help.
You will need a third table, that manages the relation between SKU and products, as a product may be part of more than one SKU (I guess). You have to model a m:n-relation.
product
id
name
price
...
sku
id
name
price
...
sku_product
id
sku_id
product_id
If I'm reading this right, you'll need a SKU table and a products table, and the products table will have a foriegn key to the SKU table.