Here is an example of what I have (take Stack Overflow). I have 2 tables, Questions
and Answers
. I also have a Comments
table. The Comments table will reference both Questions and Answers.
How should I set up the database? Have 2 columns in Comments, a QuestionId and AnswerId. Have one table for both Questions and Answers? Have a table in between that somehow tells me Question or Answer?
EDIT: Found the SO Data explorer, it uses one table for both Questions and Answers ... I just don't like the POSTS
table having so many NULLS in it. Does that have any negative effects, like on performance?
StackOverflow models the questions and answers as being the same entity: POSTS
. They have identical properties, aside from indicating the answer where accepted/granted.
Comments get their own table, and relate to the respective post using a foreign key -- the post_id
.
Without needing to load the monthly SO dumps, you can view (and query) the SO schema via the StackExchange Data Explorer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With