doucaishou0074 2016-06-17 16:19
浏览 28
已采纳

MySQL:使用主数据库和辅助数据库设计应用程序[关闭]

I'm building an application for a bakery company using CodeIgniter (PHP) and MySQL. The company has about 250 franchises. I've considered the following aspects when designing the databases:

  • Each franchise must have its own data, since they are independent from each other
  • All their products are shared between all the franchises, meaning there's only one menu
  • Each franchise will have their own stock counting
  • There'll be 3 different dashboards for the application: An administrative dashboard and a sales dashboard for each franchise, and one only for the main company, which will contain all franchises' reports.

I've designed a Primary Database with all their products, franchises and users that will have access to the application. Each user will be assigned to a franchise and a dashboard.

Then, each franchise will have a Secondary Database, with their stock counting, sales, customers, etc. All franchises will have their own database.

With this, the application will work as it follows:

  • User will access the app login page, and will be requested to enter the franchise id, his login and password.
  • All sales will be "duplicated" to de the primary database, allowing the company to keep track of all their franchises.

My questions are:

  1. Assuming that all databases will be hosted at the same server, is it a good practice to have separate databases for each franchise? It's better to have different users assigned to each database, or only one user is enough?

  2. Can i store all franchise database's names on the primary database, and then create a custom login model, that will set a second database connection according to which database the franchise is assigned to?

  • 写回答

1条回答 默认 最新

  • dongyue4964 2016-06-17 16:32
    关注

    1) This would be bad practice.

    • By having multiple databases, you have to duplicate table design and future changes into all those databases as you go, instead of updating in one place. If you find yourself duplicating data, you probably have a design problem, and you add a lot of complexity.
    • If you store all the data in a single database, you can add a "store_id" field to your tables, designating which store the data belongs to. For individual store users, you can filter by this field. If a user is responsible for several stores, you can easily consolidate their data individually under a single log-in, because the data is available in the same database and table.
    • Because the data is consolidated, you will not have to duplicate data, and company-wide reports and dashboards are much easier to generate and maintain

    2) Using one database, this extra work and complexity isn't necessary. And you eliminate a huge area of problems and troubleshooting.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 镍氢电池充电器设计实物使用原理
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号