MySQL Database design – Opinions

I’m working on a web application for our business with my brother. Our application is pretty simple, and will be developed with php and mysql.

  • Clients and providers ABMs
  • Articles Inventory (we do not manage stock, because we resell from our providers)
  • Purchases
  • Account balance for our clients and providers

I’m stuck on accounting tables… Here is my model:

database design
I’m in doubt about the account table; I’m thinking about use a trigger when purchases change Status (delivered to client) then updating the Account balance but I don’t know if this model is good for managing Accounts for my Clients.

I’m looking for opinions about my mistakes!! Thank you.

2

  • Entity names should be singular (client, purchase, etc. not clients, purchases, etc. )

  • Relationship from purchase_article to purchase should be one to many ( being purchase the one end )

  • Relationship from purchase_article to article should be one to many ( being article the one end )
  • Relationship from provider_article to article should be one to many ( being article the one end )
  • Relationship from provider_article to provider should be one to many ( being provider the one end )
  • provider_article Pk should be (idProvider, idArticle), if you insist on using a surrogate then be sure to create an unique constraint on (idProvider, idArticle)
  • What’s the difference between Phone and Telephone ? Seems like violating 1FN to me
  • What’s the difference between unitPrice and Price ?
  • Are you sure relationship between Purchase and Account is not inverted ?
  • If you insist on having a surrogate PK on client, provider, etc., be sure to create unique constraint on business key to avoid duplicates.

2

I wouldn’t comment on minor details that you can fix later.
There are several structural issues here:

  1. Why do you have a PurchaseUnitPrice in Purchase? This should be on purchaseArticle
  2. Similarly why do you have a PurchaseQuantity in Purchase? This should also be on purchaseArticle
  3. Some thing tells me UnitPrice is the price you got from the provider and price is the price you sell. If that is true, do NOT put in article the profit, if you want an argument, we can talk further to explain
  4. Purchase status shouldn’t be a boolean. You might want to have several options later such as ‘unpaid’, ‘partial-paid’, ‘returned’, etc
  5. I assume you have a table providerArticle because an article might come from several providers. This way, make sure PurchaseArticle has a relationship with ProviderArticle not Article because you want to know the exact provider providing the article that you just sold. If my assumption is not true, simply make a many-to-many relationship between the article and the provider
  6. Account should have a one-to-one relationship with Client' not withPurchase`
  7. If you really want to keep track of the payments of each purchase, put a one-to-many relationship from Purchase to Payment (a new table entity)

1

I think you need to to do a bit more analysis as to how time affects your model.

  • An offer to sell is at the current price
  • An item (or group of items) is sold at a particular price that won’t ever change.
  • You seem to be heading down the right track with the total price being in the purchases table, but then purchases_articles links to a table that has price and profit fields that may no longer be relevant.

What I am highlighting is that it is necessary to copy fields into “logging” tables, even though this looks like denormalisation. Classical data modelling theory tends to ignore this inconvenient reality..

You could use the two foreign keys as a combined primary in providers articles. This to make sure you only have one of each provider article. Otherwise you could get duplicates with just a different ID. And try to use human readable IDs (like email addresses). Besides that I don’t really see anything besides maybe the decimal-float thing.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật