I should start by saying that I am fairly new to SQL and databases. I read a lot and I have narrowed down my db design and questions. I will now try to explain.
So I am trying to build the 'typical' movie/film database (for SQL server).
Every film can have many actors, and every actor can participate in many films. The same for directors and genres. (many-to-many relationship with dbo.Films)
Film also has date and budget that are considered as one-to-one relationship (I put them in the dbo.Films).
Actors can have 1 fname, 1 lname and 0 or more email addresses. Directors have 1 fname and 1 lname. You can see my design in the image below (PK is the primary key).
1) How is my design and way of thinking so far?
2) How should I design the dbo.Emails table? If I am not mistaken this has an one-to-many relationship with actors.
3) Let's say I want to get all information I can (title, date, budget, actor(s), director(s), genre(s)) for a single movie, all in one row/line. I guess I have to use INNER JOIN. I tried the following but I got multiple rows of the same actor but different i.e. genre (in fact I think I get all combinations possible). I use Temp just to get rid of the (film) id column from the results. Is it too complicated or am I missing something?
IF OBJECT_ID('dbo.Temp', 'U') IS NOT NULL
DROP TABLE dbo.Temp
SELECT f.*, a.fname, a.lname, g.name INTO Temp
FROM [Video].[dbo].[films] f
INNER JOIN [Video].[dbo].[film_actor] af
ON f.id = af.film_id
INNER JOIN [Video].[dbo].[actors] a
ON af.actor_id = a.id
INNER JOIN [Video].[dbo].[film_genre] gf
ON f.id = gf.film_id
INNER JOIN [Video].[dbo].[genres] g
ON g.id = gf.genre_id
WHERE f.title = 'SomeMovie'
ALTER TABLE Temp
DROP COLUMN id
/* Get results and drop temp table */
SELECT * FROM Temp
DROP TABLE Temp