简体   繁体   English

寄售库存的数据库架构

[英]Database Schema for Consignment Inventory

I'm developing a consignment inventory for hospitals, 我正在为医院开发寄售清单,

The infrastructure is this: 基础结构是这样的:

Multiple Suppliers
Multiple Warehouses
Multiple Hospitals

I'm stuck on deciding whether to make a separated stock tables for EACH hospitals and warehouses or store them all in one stock table . 我一直在决定是为每个hospitalswarehouses制作单独的stock tables ,还是将它们全部存储在one stock table

My current plan is this: 我当前的计划是这样的:

They are all going to read on a single item table for general item information only, then the stocks, stock movements, consign orders, employees, patients will have separate tables per hospital/warehouses. 他们将仅在单个item table上阅读以获取常规项目信息,然后每个医院/仓库的库存,库存移动,寄售订单,员工,患者将有单独的表。

Example: 例:

Separated Tables 分隔表

tbl_items //centralized item information
tbl_suppliers //centralized supplier information
tbl_warehouse1id_stocks
tbl_warehouse1id_stockmovements
tbl_warehouse2id_stocks
tbl_warehouse2id_stockmovements
tbl_hospital1id_stocks
tbl_hospital1id_stockmovements
tbl_hospital1id_employee
tbl_hospital1id_patients
tbl_hospital2id_stocks
tbl_hospital2id_stockmovements
tbl_hospital2id_employee
tbl_hospital2id_patients

Merged Tables 合并表

tbl_items //centralized item information
tbl_suppliers //centralized supplier information
tbl_warehouse_stocks //where warehouse_ids are primary keys
tbl_warehouse_stockmovements //where warehouse_ids are primary keys
tbl_hospital_stocks //where hospital_ids are primary keys
tbl_hospital_stockmovements //where hospital_ids are primary keys
tbl_hospital_employee //where hospital_ids are primary keys
tbl_hospital_patients //where hospital_ids are primary keys

which is better? 哪个更好? for maintaining, speed optimization etc.? 用于维护,速度优化等? my current opinion is that the separated approach is better because why should (for example) hospital1 search for their certain stock of items to the pool of stocks of all hospitals? 我目前的观点是,分开的方法更好,因为例如(医院)为什么要从所有医院的库存中搜索他们的特定物品库存? does this affect the speed? 这会影响速度吗? if hospital1 tries to query their entire stock record, it will affect the query time of other hospital because hospital1 is currently searching for their records. 如果hospital1试图查询其全部库存记录,则将影响其他医院的查询时间,因为hospital1当前正在搜索其记录。 of course indexing should help but still. 当然索引应该有帮助,但仍然可以。

EDIT: 编辑:

The server resides on a single location and its a web-based system. 该服务器位于单个位置,并且其基于Web的系统。

I would highly recommend taking the MERGED TABLES approach that you've laid out. 我强烈建议您采用您提出的合并表格方法。

Disadvantages of Separate Tables: 单独表的缺点:

  • Every time a new warehouse/hospital is built or added to the tracking system, you have to add new tables to your schema 每次新建一个仓库/医院或将其添加到跟踪系统时,都必须向架构中添加新表
  • Writing a query to count the stock of a single item across all hospitals or warehouses now because a much more complex query (unions/joins through every table). 现在编写查询以计算所有医院或仓库中单个项目的库存,因为查询要复杂得多(每个表中的联合/联接)。 Combine this with the fact that a new warehouse may be added to the system (previous point), you now have to update all these queries individually 结合将新仓库添加到系统这一事实(上一点),您现在必须分别更新所有这些查询
  • How will your web back-end layer know which table to query? 您的Web后端层如何知道要查询的表? This sounds like you would be going down the path of dynamic query generation and will be adding yet more complexity to your code base. 听起来您将沿着动态查询生成的道路前进,并将为您的代码库增加更多的复杂性。

Unless you have significant constraints that you haven't laid out (extremely large db with billions of rows or poor hardware that you can't scale up), indexes are designed to exactly help with this scenario. 除非您有尚未布置的重大约束(拥有数十亿行的极大型数据库或无法扩展的不良硬件),否则索引将专门为这种情况提供帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM