根据另一个表

时间:2017-07-31 19:13:17

标签: mysql mariadb

我需要在MariaDB中创建两个表companieslocations

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 123company_id 1company abc相关联, location_id 729 company_id 2company xyz相关联。因此,location_id company的{​​{1}}应仅接受值abc12。同样,3 location_id的{​​{1}}也应仅接受值companyxyz72并非由他们自己独有,而是9location_id的组合。有什么方法可以用location_id或类似方法设置这些表来实现这个目标吗?

0 个答案:

没有答案