dongpai1942 2015-09-03 12:11
浏览 142
已采纳

MySQL数据库中的父子结构或序列化数组?

I am trying to make a good decision about how to structure my MySQL database.

I can best explain this by example:

I have a table called customers. A customer can control one or more sites. Sites has his own table. The tables customers and sites have a primary key id (AUTO-INCREMENT). Most customers can modify multiple "sites" and we are growing towards 100.000 customers. All I need to do with this information is to check if a customer can edit a site.

The question is: how can I store my data best if I want to keep the queries to a minimum and the performance best? 1. I create a serialized array of all "sites" that a customer can edit and put it in a column in customers table. 2. I create a child-table for customers called customer-site in which I write all site_id's that the customer has access to.

As you probably can read I don't have a lot of knowledge, so any information why is very appreciated!

Best regards, Abayob

  • 写回答

2条回答 默认 最新

  • duadpnld426905 2015-09-03 12:23
    关注

    You should create a permissions table which will hold two columns short_name, name. You should create another table which will hold the customer permissions to sites customer_permission_site with customer_id, site_id, permission_short_name. Then check with the short name field from your code if the user has permissions.

    Your short_name field in permissions table will be primary key for the table.

    Benefits for this architecture

    1. You can easily set an user to a site for edit, delete etc permissions.
    2. You can set permissions to be given a user to a site in permissions table
    3. Normalized & easy to search & retrieve.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 这个复选框什么作用?
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下