Reputation: 5150
Table 1 I have a table housing all of my dealers and roadshows. I am attempting to add the ability to add an event at these locations. This table has location_id
.
To do this I created another table.
Table 2 In this new table I have an id, and an event_location_id
.
Which way do I make the relationship?
I want to be able to daisy chain from Table1.Table2.count() in asp.net MVC.
In which table do I make the foreign key relationship?
Upvotes: 0
Views: 58
Reputation: 37020
In a one-to-many relationship, the primary key is held in the 'one' table, and the foreign key is held in the 'many' table. So if a location can have many events, you would have a column in the Event
table called LocationId
which would map to the location_id
primary key of the Location
table.
Upvotes: 1
Reputation: 18155
Assuming that location_id
is the primary key of Table 1 you would want to add a foreign key to Table 2 on the event_location_id
that references location_id
of Table 1.
Having said that, a table that houses dealers and roadshows doesn't sound like it's been designed correctly. It seems like it would make more sense to have a dealers table, a roadshows table, a relationship between them, and events that hang off of one or the other.
Upvotes: 1