我需要在MariaDB中创建两个表companies
和locations
。
companies
+------------+-------------+--------------+
| company_id | location_id | company_name |
+------------+-------------+--------------+
| 1 | 2 | abc |
| 2 | 9 | xyz |
+------------+-------------+--------------+
locations
+-----+-------------+---------------+------------+
| key | location_id | location_name | company_id |
+-----+-------------+---------------+------------+
| 1 | 1 | London | 1 |
| 2 | 2 | Hong Kong | 1 |
| 3 | 3 | Berlin | 1 |
| 4 | 7 | Hong Kong | 2 |
| 5 | 2 | London | 2 |
| 6 | 9 | NY | 2 |
+-----+-------------+---------------+------------+
<location_id
1
,2
和3
与company_id
1
与company
abc
相关联, location_id
7
,2
和9
company_id
2
与company
xyz
相关联。因此,location_id
company
的{{1}}应仅接受值abc
,1
和2
。同样,3
location_id
的{{1}}也应仅接受值company
,xyz
和7
。 2
并非由他们自己独有,而是9
和location_id
的组合。有什么方法可以用location_id
或类似方法设置这些表来实现这个目标吗?