多对多关系
我有下表 - 演员、女演员、导演和演员电影。
前两个表与电影表具有多对多关系。
所以我创建了 Celebrity_Movie 表,其主键为 所有这些表作为外键。
所以我的问题是如何插入记录 在 Celebrity_Movie 表中。
因为可以有多个男演员、女演员 一部电影。例如,电影“Race”有多个演员和演员。多名女演员。那么如何 在 Celebrity_Movie 表中填充“Race”电影的数据?
Actor table
Actor_id Actor_name
1 Amitabh
2 Akshay kumar
3 Hritik roshan
4 Amir khan
5 R. Madhavan
6 Sharman joshi
7 Ajay devgan
8 Tushar
9 Arshad varsi
Actress
Actress_id Actress_name
1 Aishwairya
2 Katrina
3 Bipasha
4 Sameera reddy
5 Kareena
6 Amrita rao
Director
Direct_id Direct_name
1 Abbas_Mustan
2 Priyadarshan
Movie
Movie_id Movie_name
M1 Race
M2 Golmal2
M3 3 Idiots
I have the following table - Actor, Actresses, Director & Movie.
First 2 tables have many to many relationship with movie table.
So i have created Celebrity_Movie table which has primary key of
all these tables as foreign key.
So my question is how can I insert records
in Celebrity_Movie table.
Because there can be multiple actors, actresses in
a movie. e.g. Movie 'Race' has multiple actors & multiple actresses. So how to
fill data in Celebrity_Movie table for 'Race' movie?
Actor table
Actor_id Actor_name
1 Amitabh
2 Akshay kumar
3 Hritik roshan
4 Amir khan
5 R. Madhavan
6 Sharman joshi
7 Ajay devgan
8 Tushar
9 Arshad varsi
Actress
Actress_id Actress_name
1 Aishwairya
2 Katrina
3 Bipasha
4 Sameera reddy
5 Kareena
6 Amrita rao
Director
Direct_id Direct_name
1 Abbas_Mustan
2 Priyadarshan
Movie
Movie_id Movie_name
M1 Race
M2 Golmal2
M3 3 Idiots
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要三个多对多关系表,因为您希望将导演、演员和女演员表与电影相关联。
有几种方法可以做到这一点:
1) 最好的方法可能是简单地创建三个不同的关系表:
其他方法更为复杂,其中单个连接表用于不同类型的连接(演员、女演员、导演)。首先,我推荐三个连接表。
添加如果您只想对男演员/女演员进行多对多,最简单的方法是重新定义“人才”表而不是男演员/女演员表来处理两者:
You need three many-to-many relationship tables because you want to relate Director, Actor and Actress tables to Movies.
There are several ways to do this:
1) Probably best is to simply create the three different relationship tables:
Other ways are more complicated where a single join table is used for the different types of joins (Actor, Actress, Director). To start with, I recommend the three Join tables.
Added If you only want to many-to-many for the actor/actresses, the easiest way is to redefine a "Talent" table instead of the Actor/Actress tables to handle both:
正如其他人之前所说,您需要三个多对多表。
我是否可以建议您考虑仅使用一个人表并包括该人的性别。此外,您可以在关系表中添加一个“角色”,以指示该人在给定电影中扮演的角色(演员/导演等)。
As other previously has stated you need three many-to-many tables.
Might I suggest that you consider using only one person table and include the sex of the person. Furthermore you could add a 'role' to the relation table to indicate what role the person has (actor/director etc.) in a given movie.