我有一個應用程序,收集關於學校,團隊和球員的數據。 可以有學校,團隊和球員級別的定製問題。數據庫結構反饋
我已經想出了2個數據庫設計,我只是對每個設計的優缺點感興趣,然後才走下那條路。
設計1
這種設計具有的一切不同的表。數據庫設計看起來很明確,但我希望代碼中會有很多複製來支持3組基本相同的表。
表:
SchoolQuestions (id, questiontext, length, is_required)
SchoolAnswers(id, school_id, school_question_id, answer)
TeamQuestions (id, questiontext, length, is_required)
TeamAnswers(id, team_id, team_question_id, answer)
PlayerQuestions (id, questiontext, length, is_required)
PlayerAnswers(id, player_id, player_question_id, answer)
設計2
這種設計存儲在兩個表的一切。
的Questions.type字段是ENUM('SCHOOL', 'PLAYER', 'TEAM')
在解答表,僅schoold_id,TEAM_ID或player_id之一可以是不爲空。
這似乎是最簡單的解決方案,但確實有冗餘列,所以看起來有點亂
表:
Questions (id, type, questiontext, length, is_required)
Answers(id, school_id, team_id, player_id, question_id, answer)
任何反饋表示讚賞,或者如果你有更好的建議改進設計解。
良好的思想,關於三列到1個通用ID – bumperbox