我有三個對象:City,Channel,Genre。關係:城市有很多頻道和流派,頻道和流派可能在幾個城市。頻道有很多流派,但流派可能有很多頻道。SQL多個MANY_TO_MANY關係
我設計一個數據庫:
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
我不知道,這個正確,誰可以指定我的錯誤?
決心:
我明年重新設計我的數據庫:
tblChannel:
id,
name
tblGenre:
id,
name
tblCity:
id,
name
tblCityChannelGenre:
id,
cityId, // NOT NULL
channelId,
genreId
這個佈局解決下一個問題:
- 我可以單獨創建的entites(通道可能沒有流派,類型 可能沒有頻道)
- 城市可能有列表的頻道, 這不是由流派定義的,而是與流派相反的。
http://stackoverflow.com/questions/14644293/sql-server-query-for-many-to-many-relationship –
它真的看起來像我需要?我問了數據庫設計。 –