Question

I have a three objects: City, Channel, Genre. Relations: City has many Channels and Genres, and Channel and Genres may are in several Cities. Channels has many Genres, and but Genre may has many Channels.

I designed next database:

tblChannel:
  id,
  name

tblGenre:
  id,
  name

tblCity:
  id,
  name

// City and Channel MANY_MANY
tblCityChannel:
  id,
  cityId,
  channelId

// City and Genre MANY_MANY
tblCityGenre:
  id,
  cityId,
  genreId

// Channel and Genre MANY_MANY
tblChannelGenre:
  id,
  channelId,
  genreId

I am not sure that this correctly, who can specify my mistakes?

RESOLVE:

I redesigned my database by next:

tblChannel:
  id,
  name

tblGenre:
  id,
  name

tblCity:
  id,
  name

tblCityChannelGenre:
  id,
  cityId, // NOT NULL
  channelId,
  genreId

That layout solves next problems:

  1. I may create entites separately (channel may not have genre, genre may not have channels)
  2. City may have list of channels, which are not be defined by genre, and with genres conversely.
Was it helpful?

Solution

your model is correct if it is a real m:m relationship between all 3 entities. however in the real world it is unlikely. most likely you have a hierarchy (like a tree) where you only have 2 m:m relationships and the third one is implied or you have a relationship between 3 tables so you need a table with 3 col key (not 3 tables with 2 col keys). try to understand you data better and you'll see what the correct model is. again, it could be just fine...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top