mysql - Admin多属性MYSQL如何高效连接

标签 mysql sql database

我有一个名为“admin”的表和另一个“property”。

那么“属性(property)”可能由不同的管理员拥有。

那么,连接它的最佳方式是什么?

使用 'property.admin_id' = 1,2,3 效率不高,因为我无法在需要时在 WHERE 上进行 SELECT。

也许为每个管理员创建额外的行?

谢谢。

最佳答案

使用第三个表权限,每个管理/属性组合一行作为外键引用。

管理员

| id | name |
|----|------|
| 1  | John |
| 2  | Ana  |
| 3  | Dan  |

属性

| id | name       |
|----|------------|
| 1  | Property 1 |
| 2  | Property 2 |
| 3  | Property 3 |

权限

| id | property_id | admin_id |
|----|-------------|----------|
| 1  | 1           | 1        |
| 2  | 1           | 2        |
| 3  | 2           | 2        |
| 4  | 2           | 3        |

关于mysql - Admin多属性MYSQL如何高效连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49840553/

相关文章:

时间:2019-05-17 标签:c#mysqlconnectionstring问题

mysql - spark 将 1.5 亿条记录加载到 MySQL 需要 2-3 小时

mysql - 数据透视表以外的其他方式 - 增量

SQL : select when a character occurs more than once in a column

android - openOrCreateDatabase 不起作用

mysql - 为什么根据查询的日期范围不使用created_at索引?

mysql - 简单的选择查询返回空结果集?

php - 使用 mysql 中的值填充选择输入字段

sql - 从字符串中提取日期并将其插入Microsoft SQL Server 2012字段

c++ - 事务性、内存中、对象/键/值存储库?