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条)

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图